Last active
January 3, 2016 21:09
-
-
Save rossnz/8519905 to your computer and use it in GitHub Desktop.
Convert a Unix datestamp to a .Net DateTime object in PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-UnixDate ($UnixDate) { | |
[timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($UnixDate)) | |
} | |
# It returns a PowerShell DateTime object, which can be manipulated | |
# using the standard DateTime methods, eg | |
PS> $logtime = Get-UnixDate 1269313872.893866062 | |
PS> $logtime | |
Tuesday, 23 March 2010 4:11:12 p.m. | |
PS> $logtime.IsDaylightSavingTime() | |
True | |
PS> $logtime.dayofweek | |
Tuesday | |
PS> $logtime.minute | |
11 | |
PS> $logtime.tostring("g") | |
23/03/2010 4:11 p.m. | |
PS> $logtime.DayOfYear | |
82 | |
PS> $logtime.AddDays(-30) | |
Sunday, 21 February 2010 4:11:12 p.m. | |
PS> ($logtime.adddays(14)).isdaylightsavingtime() | |
False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment