Created
August 8, 2019 21:34
-
-
Save craig-martin/3e75eac057957d515dd33357832082e6 to your computer and use it in GitHub Desktop.
Convert Epoch to DateTime with PowerShell
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 ConvertEpoch-ToDateTime | |
{ | |
<# | |
.Synopsis | |
Converts an epoch to a DateTime | |
.DESCRIPTION | |
Needed this for validating JWT tokens using PowerShell. Times were specified as NumericDate per RFC7519 (https://tools.ietf.org/html/rfc7519#section-4.1.4) | |
.EXAMPLE | |
ConvertEpoch-ToDateTime -NumericDate 1565298477 | |
.EXAMPLE | |
#Convert an Epoch to the local time | |
(ConvertEpoch-ToDateTime -NumericDate 1565298477).ToLocalTime() | |
#> | |
[CmdletBinding()] | |
[Alias()] | |
[OutputType([int])] | |
Param | |
( | |
# Param1 help description | |
[Parameter(Mandatory=$true, Position=0)] | |
[double]$NumericDate | |
) | |
([DateTime]('1970,1,1')).AddSeconds($NumericDate) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment