6 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

  1. I was able to get it to work, using what another separate article suggested for another language by removing the last 3 digits. In the parentheses where the 13 character integer string is, add “/ 1000” at the end, then run it. It worked for me.

    What I ran in PS:
    $oUNIXDate=(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds(1627505005033 / 1000))

    What I got when I ran $oUNIXDate:
    Wednesday, July 28, 2021 8:43:25 PM

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.