Last active
August 15, 2021 20:50
-
-
Save quonic/74884d13fbf11c0c38b3349152b93c60 to your computer and use it in GitHub Desktop.
Created this to help convert UNIX time to and from Windows time when interfacing with data from API's that output time in UNIX time.
This file contains 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 ConvertTo-UnixTime { | |
[OutputType([int64])] | |
Param( | |
# Date in UNIX time | |
[Parameter(Mandatory, | |
ValueFromPipeline=$true)] | |
[DateTime] | |
$DateTime | |
) | |
[Math]::Floor([decimal](Get-Date($DateTime).ToUniversalTime() -UFormat "%s")) | |
} |
This file contains 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 ConvertTo-WindowsTime { | |
[OutputType([DateTime])] | |
Param( | |
# Date in UNIX time | |
[Parameter(Mandatory, | |
ValueFromPipeline=$true)] | |
[int64] | |
$ticks | |
) | |
[DateTime]::new(1970, 1, 1, 0, 0, 0, 0, [System.DateTimeKind]::Utc).AddSeconds($ticks).ToLocalTime() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment