Converting dates/times into ticks using the PowerShell Get-Date applet is simple. However, how do you do the opposite operation; converting the ticks back into a date and time?
+5
A:
[DateTime]10000000000
Monday, January 01, 0001 12:16:40 AM
Just cast the number into a DateTime
. The DateTime
single-parameter constructor takes a long
as number of ticks.
Lee
2009-07-16 22:05:14
+1 So it does. http://msdn.microsoft.com/en-us/library/aa326681(VS.71).aspx
Robert Harvey
2009-07-16 22:12:16
I suspected that it was something simple. This is what happens when you try to learn PowerShell, .NET, and Active Directory at the same time..
mkClark
2009-07-16 22:54:01
Welcome to the stack! PowerShell does take a little getting used to, but I really think that it brings a lot of flexibility and strength to Windows that wasn't there before unless you wanted to deal with some sort of Unix toolset like MKSToolkit.
Lee
2009-07-16 23:06:25
A:
Note that you can use the Get-Date
cmdlet to also do the reverse operation:
PS> Get-Date 634141193308872671
Mittwoch, 7. Juli 2010 17:08:50
Joey
2010-07-07 15:09:30
A:
You can also use the New-Object cmdlet:
PS > get-date
Friday, July 09, 2010 12:01:42 AM
PS > (get-date).ticks 634142305097923801
PS > New-Object System.DateTime 634142305097923801
Friday, July 09, 2010 12:01:49 AM
Shay Levy
2010-07-08 21:03:10