Created
October 8, 2021 13:12
-
-
Save rasmuseeg/7e8040a6b4cb1158272f901c9c9a17a4 to your computer and use it in GitHub Desktop.
Converts unix or epoch times to DateTime object.
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 ConvertFrom-UnixTime { | |
[CmdletBinding(DefaultParameterSetName = "Seconds")] | |
param ( | |
[Parameter(Position = 0, | |
ValueFromPipeline = $true, | |
Mandatory = $true, | |
ParameterSetName = "Seconds")] | |
[int] | |
$Seconds, | |
# Parameter help description | |
[Parameter(Position = 0, | |
ValueFromPipeline = $true, | |
Mandatory = $true, ParameterSetName = "Miliseconds")] | |
[bigint] | |
$Miliseconds | |
) | |
Begin { | |
$date = (Get-Date "1970-01-01 00:00:00.000Z") | |
} | |
Process { | |
switch ($PSCmdlet.ParameterSetName) { | |
"Miliseconds" { | |
$date = $date.AddMilliseconds($Miliseconds) | |
} | |
Default { | |
$date = $date.AddSeconds($Seconds); | |
} | |
} | |
} | |
End { | |
$date | |
} | |
} | |
Set-Alias -Name epoch -Value ConvertFrom-UnixTime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment