# get-datetimeticks.ps1
# displays ticks from date/time
# Thomas Lee - tfl@psp.co.uk
# setup up dates
$centuryBegin = new-object System.DateTime 2001, 1, 1
$currentDate = [System.DateTime]::Now
$elapsedTicks = $currentDate.Ticks - $centuryBegin.Ticks
$elapsedSpan = new-object system.TimeSpan $elapsedTicks
# display output
"Current date: {0}" -f $currentdate
"Elapsed from the beginning of the century to {0:f}:" -f $currentDate
" {0:N0} nanoseconds" -f $($elapsedTicks * 1000)
" {0:N0} ticks" -f, $elapsedTicks
" {0:N2} seconds" -f $elapsedSpan.TotalSeconds
" {0:N2} minutes" -f $elapsedSpan.TotalMinutes
" {0:N0} days, {1} hours, {2} minutes, {3} seconds" -f $elapsedSpan.Days, $elapsedSpan.Hours,$elapsedSpan.Minutes, $elapsedSpan.Seconds
This script produces the following output:
PS C:\Documents and Settings\LeeT> D:\foo\get-datetimeticks.ps1
Current date: 20/04/2008 11:12:29
Elapsed from the beginning of the century to 20 April 2008 11:12:
2,303,827,494,000,000,000 nanoseconds
2,303,827,494,000,000 ticks
230,382,749.40 seconds
3,839,712.49 minutes
2,666 days, 11 hours, 12 minutes, 29 seconds