views:

52

answers:

2

I have 2 XML files I'm reading - one has a date/time attribute that's readable (ex. May 1, 2010 12:03:14 AM) and the other... not so much (ex. 1272686594492). Both files have the complicated date/time format, but only the newer one has the readable version. I cannot figure out how to make the complicated version readable. Any ideas?

The numbers are in the pastbin below.

http://pastebin.com/HMLEAGhf

Thanks!

+4  A: 

Looks like what you have is the number of milliseconds from midnight, January 1st 1970 (which is kind of like UNIX time, except it's in milliseconds, not seconds). For example:

long l = 1272740342854;
DateTime dt = new DateTime(1970, 1, 1).AddMilliseconds(l);
Console.WriteLine(dt);

When I plug that in, it's actually a couple of hours off so I guess there must be some kind of timezone offset applied as well.

Dean Harding
Whoa, I never would have thought to count milliseconds from 1/1/1970 to calculate a DateTime string. And yeah, it's 4 hours off for me, but I can work with that. How did you figure it out? Thanks by the way!
duckwizzle
@duckwizzle, well, to figure out if it's seconds or milliseconds, you just subtract one number from another. That gives a different of about a million for a few hours so it's gotta be milliseconds. Then, you just subtract the milliseconds from the final date to get the "epoch" time (e.g. `new DateTime(2010, 5, 1, 0, 3, 14).Subtract(TimeSpan.FromMilliseconds(1272686594492))`). I guessed 1970 as the "real" epoch cause that's Unix time, and it's pretty common.
Dean Harding
Ooooh, alright, thanks a lot man
duckwizzle
A: 

My guess is the number represents the seconds since 1st of january 1970

so 1276648174733 = June 16, 2010 00:29:34

http://www.mbari.org/staff/rich/utccalc.htm

Arkain