What is this UTC time format?
I am parsing an XML file that has a field called UTCTime and contains the value 1311346453064. It also comes with a field called UTC that开发者_开发问答 contains the value 2011-07-22T10:54:13.064-04:00 which is a complete .Net DateTimeOffset I believe. The first field I can't figure out though. What generates a date in that way? It's too large to be a unix timestamp since it adds about 41 millenia to 1/1/1970. Any help in identifying it or how I can convert it to a datetime without using that second field would be a great help! Thanks.
It is equivalent to the unix timestamp [i.e. a straight count since 1970] but in milliseconds instead of seconds.
$ date -d @1311346453
Fri Jul 22 10:54:13 EDT 2011
Ending with 3064
made it obvious to me.
So, to convert in .NET you would use
static readonly DateTime epoch = new DateTime(1970,1,1,0,0,0,
DateTimeKind.Utc);
long value = 1311346453064L;
var ts = new TimeSpan(value*TimeSpan.TicksPerMillisecond);
var dt = epoch + ts;
Or, slightly more efficiently at a cost of some readability
const long epochTicks = 621355968000000000L;
var dt = new TimeSpan(value*TimeSpan.TicksPerMillisecond+epochTicks,
DateTimeKind.Utc);
Note that this discards the timezone information (the offset of -04:00
) in the other field.
Javascript example:
D:\ :: more > date.js
WScript.Echo( new Date().getTime() );
^Z
D:\ :: cscript date.js
1311975458665
This is the number of milliseconds since 01.01.1970.
精彩评论