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

4 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

      1. It would be 50000 years later.

        People using recently released Powershell 7.1 could try
        Get-Date -UnixTimeSeconds 1537615930

Leave a Reply to Adam Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.