Skip to content

Instantly share code, notes, and snippets.

@craig-martin
Created August 8, 2019 21:34
Show Gist options
  • Save craig-martin/3e75eac057957d515dd33357832082e6 to your computer and use it in GitHub Desktop.
Save craig-martin/3e75eac057957d515dd33357832082e6 to your computer and use it in GitHub Desktop.
Convert Epoch to DateTime with PowerShell
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