unixman_again Posted May 26, 2016 Posted May 26, 2016 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?
DJ-1701 Posted May 26, 2016 Posted May 26, 2016 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.
biz Posted May 26, 2016 Posted May 26, 2016 (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 May 26, 2016 by biz 2
DJ-1701 Posted May 26, 2016 Posted May 26, 2016 (edited) Try this instead (Get-Date -Date 01/01/1970).AddSeconds(1464276580) Ah, @biz ninjaed me it seems. Edited May 26, 2016 by DJ-1701 2
DJ-1701 Posted May 26, 2016 Posted May 26, 2016 Heh, sorry! Haha, you got the answer for him, that's what matters. Great minds think alike.
unixman_again Posted May 27, 2016 Author Posted May 27, 2016 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! 1
DJ-1701 Posted May 27, 2016 Posted May 27, 2016 So X+0 is fine but X isn't !?! What can we say but... Microsoft.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now