Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - date time conversion

Reply
 
Old 11-14-2007   #1 (permalink)
Justin Rich


 
 

date time conversion

so im working with this system that spits out 1195047591 as a date/time and
im not really sure how to convert that in to GMT. that time was taken at
about 8:39am today (11/14)

Thanks
Justin



My System SpecsSystem Spec
Old 11-14-2007   #2 (permalink)
Bob Butler


 
 

Re: date time conversion

"Justin Rich" <jrich523@xxxxxx> wrote in message
news:unmkkqsJIHA.1168@xxxxxx
Quote:

> so im working with this system that spits out 1195047591 as a date/time
> and im not really sure how to convert that in to GMT. that time was taken
> at about 8:39am today (11/14)
looks like it's the the number of seconds since 1/1/1970 in UTC

?dateadd("s",1195047591,#1/1/1970#)
11/14/2007 1:39:51 PM

since you are 5 hours off from UTC
?dateadd("h",-5,dateadd("s",1195047591,#1/1/1970#))
11/14/2007 8:39:51 AM

My System SpecsSystem Spec
Old 11-14-2007   #3 (permalink)
Bob Butler


 
 

Re: date time conversion

"Bob Butler" <noway@xxxxxx> wrote in message
news:e3Af2tsJIHA.5624@xxxxxx
Quote:

> "Justin Rich" <jrich523@xxxxxx> wrote in message
> news:unmkkqsJIHA.1168@xxxxxx
Quote:

>> so im working with this system that spits out 1195047591 as a date/time
>> and im not really sure how to convert that in to GMT. that time was taken
>> at about 8:39am today (11/14)
>
> looks like it's the the number of seconds since 1/1/1970 in UTC
>
> ?dateadd("s",1195047591,#1/1/1970#)
> 11/14/2007 1:39:51 PM
>
> since you are 5 hours off from UTC
> ?dateadd("h",-5,dateadd("s",1195047591,#1/1/1970#))
> 11/14/2007 8:39:51 AM
Sorry, lost track of what group I was in so the VB syntax for manipulating
dates isn't going to work in powershell. Hopefully you get the idea anyway!

My System SpecsSystem Spec
Old 11-14-2007   #4 (permalink)
Brandon Shell [MVP]


 
 

Re: date time conversion

Either way... that number is way small for UTC

UTC from today is 128395249478332360
his number is 1195047591

Not Even close.

Maybe it would be a good idea to figure out how Justin got that number? Spits
out is kinda vague

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

BB> "Bob Butler" <noway@xxxxxx> wrote in message
BB> news:e3Af2tsJIHA.5624@xxxxxx
BB>
Quote:
Quote:

>> "Justin Rich" <jrich523@xxxxxx> wrote in message
>> news:unmkkqsJIHA.1168@xxxxxx
>>
Quote:

>>> so im working with this system that spits out 1195047591 as a
>>> date/time and im not really sure how to convert that in to GMT. that
>>> time was taken at about 8:39am today (11/14)
>>>
>> looks like it's the the number of seconds since 1/1/1970 in UTC
>>
>> ?dateadd("s",1195047591,#1/1/1970#)
>> 11/14/2007 1:39:51 PM
>> since you are 5 hours off from UTC
>> ?dateadd("h",-5,dateadd("s",1195047591,#1/1/1970#)) 11/14/2007
>> 8:39:51 AM
>>
BB> Sorry, lost track of what group I was in so the VB syntax for
BB> manipulating dates isn't going to work in powershell. Hopefully you
BB> get the idea anyway!
BB>


My System SpecsSystem Spec
Old 11-14-2007   #5 (permalink)
Bob Butler


 
 

Re: date time conversion

"Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
news:29d4f64625048c9f4b9fd59ba3b@xxxxxx
Quote:

> Either way... that number is way small for UTC
>
> UTC from today is 128395249478332360
> his number is 1195047591
>
> Not Even close.
Huh?
1195047591 seconds is just under 38 years

Jan 1, 1970 + 1195047591 seconds is Nov 14, 2007 at 13:39:51

a 5-hour offset from UTC would put that back to 8:39:51AM

My System SpecsSystem Spec
Old 11-14-2007   #6 (permalink)
Bob Butler


 
 

Re: date time conversion

"Bob Butler" <noway@xxxxxx> wrote in message
news:e3Af2tsJIHA.5624@xxxxxx
Quote:

> "Justin Rich" <jrich523@xxxxxx> wrote in message
> news:unmkkqsJIHA.1168@xxxxxx
Quote:

>> so im working with this system that spits out 1195047591 as a date/time
>> and im not really sure how to convert that in to GMT. that time was taken
>> at about 8:39am today (11/14)
>
> looks like it's the the number of seconds since 1/1/1970 in UTC
>
> ?dateadd("s",1195047591,#1/1/1970#)
> 11/14/2007 1:39:51 PM
>
> since you are 5 hours off from UTC
> ?dateadd("h",-5,dateadd("s",1195047591,#1/1/1970#))
> 11/14/2007 8:39:51 AM
>

try something along these lines:
$d=new-object System.DateTime(1970,1,1)
$d=$d.AddSeconds(1195047591)
$d=$d.ToLocalTime()

there's probably a better way; I find it very difficult to think in
"powershell" and have to translate from other languages

My System SpecsSystem Spec
Old 11-14-2007   #7 (permalink)
Bob Butler


 
 

Re: date time conversion

"Bob Butler" <noway@xxxxxx> wrote in message
news:e3Af2tsJIHA.5624@xxxxxx
Quote:

> "Justin Rich" <jrich523@xxxxxx> wrote in message
> news:unmkkqsJIHA.1168@xxxxxx
Quote:

>> so im working with this system that spits out 1195047591 as a date/time
>> and im not really sure how to convert that in to GMT. that time was taken
>> at about 8:39am today (11/14)
>
> looks like it's the the number of seconds since 1/1/1970 in UTC
>
> ?dateadd("s",1195047591,#1/1/1970#)
> 11/14/2007 1:39:51 PM
>
> since you are 5 hours off from UTC
> ?dateadd("h",-5,dateadd("s",1195047591,#1/1/1970#))
> 11/14/2007 8:39:51 AM
>

try something along these lines:
$d=new-object System.DateTime(1970,1,1)
$d=$d.AddSeconds(1195047591)
$d=$d.ToLocalTime()

there's probably a better way; I find it very difficult to think in
"powershell" and have to translate from other languages

My System SpecsSystem Spec
Old 11-14-2007   #8 (permalink)
Justin Rich


 
 

Re: date time conversion

Bob's right, the date comes out correct.

i left if vague because its from an application log for Acronis True Image
and there is no info on the log file format so all i have is this number and
my knowledge of when the task was run.

Thanks for the help guys.

Justin

"Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
news:29d4f64625048c9f4b9fd59ba3b@xxxxxx
Quote:

> Either way... that number is way small for UTC
>
> UTC from today is 128395249478332360
> his number is 1195047591
>
> Not Even close.
>
> Maybe it would be a good idea to figure out how Justin got that number?
> Spits out is kinda vague
>
> Brandon Shell
> ---------------
> Blog: http://www.bsonposh.com/
> PSH Scripts Project: www.codeplex.com/psobject
>
> BB> "Bob Butler" <noway@xxxxxx> wrote in message
> BB> news:e3Af2tsJIHA.5624@xxxxxx
> BB>
Quote:
Quote:

>>> "Justin Rich" <jrich523@xxxxxx> wrote in message
>>> news:unmkkqsJIHA.1168@xxxxxx
>>>
>>>> so im working with this system that spits out 1195047591 as a
>>>> date/time and im not really sure how to convert that in to GMT. that
>>>> time was taken at about 8:39am today (11/14)
>>>>
>>> looks like it's the the number of seconds since 1/1/1970 in UTC
>>>
>>> ?dateadd("s",1195047591,#1/1/1970#)
>>> 11/14/2007 1:39:51 PM
>>> since you are 5 hours off from UTC
>>> ?dateadd("h",-5,dateadd("s",1195047591,#1/1/1970#)) 11/14/2007
>>> 8:39:51 AM
>>>
> BB> Sorry, lost track of what group I was in so the VB syntax for
> BB> manipulating dates isn't going to work in powershell. Hopefully you
> BB> get the idea anyway!
> BB>
>

My System SpecsSystem Spec
Old 11-14-2007   #9 (permalink)
Brandon Shell [MVP]


 
 

Re: date time conversion

UTC is 100-nanoseconds from January 1, 1601
http://msdn2.microsoft.com/en-us/library/ms724284.aspx

Seconds from Jan 1, 1970 is a Unix/Linux called Epoch Time.
http://en.wikipedia.org/wiki/Unix_time

Which is exactly why I asked where he got the time format.

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

BB> "Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
BB> news:29d4f64625048c9f4b9fd59ba3b@xxxxxx
BB>
Quote:
Quote:

>> Either way... that number is way small for UTC
>>
>> UTC from today is 128395249478332360
>> his number is 1195047591
>> Not Even close.
>>
BB> Huh?
BB> 1195047591 seconds is just under 38 years
BB> Jan 1, 1970 + 1195047591 seconds is Nov 14, 2007 at 13:39:51
BB>
BB> a 5-hour offset from UTC would put that back to 8:39:51AM
BB>


My System SpecsSystem Spec
Old 11-14-2007   #10 (permalink)
Bob Butler


 
 

Re: date time conversion

"Brandon Shell [MVP]" <a_bshell.mask@xxxxxx> wrote in message
news:29d4f64625208c9f4d83fa76492@xxxxxx
Quote:

> UTC is 100-nanoseconds from January 1, 1601
> http://msdn2.microsoft.com/en-us/library/ms724284.aspx
That format isn't called UTC, it's just that the values have to be
interpreted as UTC time. To get local time you have to account for the
offset to the local time zone.

http://en.wikipedia.org/wiki/Coordinated_Universal_Time

It may be that the values aren't truly accurate UTC times and are off by
whatever leap seconds have been ignored and might be better called GMT time
instead of UTC time.


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Date time calculations PowerShell
Time and Date Settings Vista mail
Date and Time Vista General
Parsing IIS web server logs + time-series conversion PowerShell
Date and Time Tutorials


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46