Hi,
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
Michael
Hi,
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
Michael
You must be logged in to post a comment.
Hi! Another way:
$Date = (Get-Date 01.01.1970).AddSeconds(1537615930)
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.
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
It would be 50000 years later.
People using recently released Powershell 7.1 could try
Get-Date -UnixTimeSeconds 1537615930
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
That worked perfectly, thanks!