Jump to content

Recommended Posts

Posted

What is going on here?

PS C:\Windows\System32\WindowsPowerShell\v1.0> Get-Date -UFormat %s
1464276491.14383
PS C:\Windows\System32\WindowsPowerShell\v1.0> Get-Date -Date 1464276491.14383 -UFormat "%D %R"
Get-Date : Cannot bind parameter 'Date'. Cannot convert value "1464276491.14383" to type "System.DateTime". Error: "String was not recognized as a valid DateTime."
At line:1 char:15
+ Get-Date -Date <<<<  1464276491.14383 -UFormat "%D %R"
   + CategoryInfo          : InvalidArgument: ( [Get-Date], ParameterBindingException
   + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand

PS C:\Windows\System32\WindowsPowerShell\v1.0> Get-Date -Date 1464276491 -UFormat "%D %R"
01/01/01 00:02
PS C:\Windows\System32\WindowsPowerShell\v1.0> Get-Date

26 May 2016 15:29:40


PS C:\Windows\System32\WindowsPowerShell\v1.0> Get-Date -Date "26 May 2016 15:29:40" -UFormat %s
1464276580
PS C:\Windows\System32\WindowsPowerShell\v1.0> Get-Date -Date 1464276580 -UFormat "%D %R"
01/01/01 00:02
PS C:\Windows\System32\WindowsPowerShell\v1.0>

 

This site Unix Time Stamp - Epoch Converter correctly gives 1464276580 as 05/26/2016 @ 3:29pm (UTC)

 

So basically, powershell can produce unixtime but I can't get it to convert unixtime to people time. What am I doing wrong?

Posted
My assumption would be it needs to know the Unix base time and add the seconds to convert back. So you would need to get the date 1/1/1970 then add the seconds from the UTS to generate it correctly.
Posted (edited)

@DJ-1701 yep, that works

 

PS C:\Windows\System32\windowspowershell\v1.0> (Get-Date "1/1/1970").AddSeconds("1464276580")

26 May 2016 15:29:40

Edited by biz
  • Thanks 2
Posted
Try this instead :)

(Get-Date -Date 01/01/1970).AddSeconds(1464276580)

 

Ah, @biz ninjaed me it seems. ;)

 

I find this really bizarre. As we know 01/01/1970-00:00:00 is unixtime 0 and we add the unixtime (seconds) of the date we want to 0 and then it returns the correct date. So X+0 is fine but X isn't !?!

 

Anyway, thanks for all your help!

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...