Last active
June 1, 2021 15:47
-
-
Save austoonz/3b7d39f618f1eeb206c24faf9454227a to your computer and use it in GitHub Desktop.
PowerShell snippets for dealing with epoch ('01-01-1970')
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 Get-EpochTimeFrom { | |
param ( | |
[int]$Seconds | |
) | |
(Get-Date -Date '01-01-1970') + ([System.TimeSpan]::FromSeconds($Seconds)) | |
} |
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 Get-EpochTimeInSeconds | |
{ | |
param | |
( | |
[DateTime] $DateTime | |
) | |
if ($DateTime) | |
{ | |
([DateTimeOFfset]$Date).ToUnixTimeSeconds() | |
} | |
else | |
{ | |
[DateTimeOffset]::Now.ToUnixTimeSeconds() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment