2

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.

4
  • A date is a date irrespective of the programming language Commented Jul 10, 2013 at 0:05
  • 1
    @karthikr: But you do have to understand what a C#-generated timestamp like 1373338800000 means (it's not as if this is defined by JSON or anything), so it's a valid question. Commented Jul 10, 2013 at 0:09
  • if you can not help, not hinder. Commented Jul 10, 2013 at 0:10
  • 1
    In the future, it would help to show actual JSON, not an approximation. Is that Date (1373338800000) inside a string? By itself? Commented Jul 10, 2013 at 0:13

1 Answer 1

3

Looks like unix timestamp with milliseconds.

>>> import datetime
>>> datetime.datetime.fromtimestamp(int("1373338800000") / 1000)
datetime.datetime(2013, 7, 8, 20, 0)
Sign up to request clarification or add additional context in comments.

4 Comments

Almost, but you'll want to divide by 1000, because fromtimestamp takes seconds, not millis. (Edited so you don't have to.)
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…)
I need that time part of the result and not getting ignored 00:00:00.
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.