I need to convert a date from c # to python. The data format is json. The data contained in the json formatted as: / Date (1373338800000). Must be transformed into a valid date for the python.
1 Answer
Looks like unix timestamp with milliseconds.
>>> import datetime
>>> datetime.datetime.fromtimestamp(int("1373338800000") / 1000)
datetime.datetime(2013, 7, 8, 20, 0)
4 Comments
abarnert
Almost, but you'll want to divide by 1000, because
fromtimestamp takes seconds, not millis. (Edited so you don't have to.)abarnert
Note that there's no good way of telling whether this timestamp is GMT or local without some kind of outside knowledge. (For example, if you run the C# program locally and get it to dump out the current date and it comes out 9 hours in the future and you're in GMT-9, it's probably local. Of course if you live in GMT, that doesn't help…)
user2566498
I need that time part of the result and not getting ignored 00:00:00.
abarnert
@user2566498: The time part isn't ignored, nor is it 00:00:00. You've got a
datetime object representing 8 July 2013 at 20:00.
1373338800000means (it's not as if this is defined by JSON or anything), so it's a valid question.Date (1373338800000)inside a string? By itself?