Powershell: Convert UNIX Timestamp to DateTime


simple one liner to convert an UNIX Timnestap to DataTime object.

PS D:\> $oUNIXDate=(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds(1537615930))
PS D:\> $oUNIXDate
Samstag, 22. September 2018 11:32:10


Advertisment to support michlstechblog.info

3 thoughts on “Powershell: Convert UNIX Timestamp to DateTime”

    1. Keep in mind that you’re going to get a local time that way. i’m pretty sure that the Epoch is defined as jan 1, 1970 GMT.

    2. Unable to convert the number # 1589997744995 .

      $oUNIXDate=(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds(1589997744995))
      Exception calling “FromSeconds” with “1” argument(s): “TimeSpan overflowed because the duration is too long.”
      At line:1 char:1
      + $oUNIXDate=(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds(1589 …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : OverflowException

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.