Python to convert JavascriptSerializer to datetime?

Question:

My JSON file has date and time in JavascriptSerializer format as in below,

{"StartDate": "/Date(1519171200000)/",
"EndDate": "/Date(1519257600000)/",}

How to convert it to datetime like this?

"2012-04-23T18:25:43.511Z" - JavaScript built-in JSON object
"2012-04-21T18:25:43-05:00" - ISO 8601
Asked By: Karthik

||

Answers:

Got a solution for this, though may not be an efficient one but still helped me.

>s_time = re.sub("D", '', "/Date(1519171200000)/")
>d_time = datetime.datetime.fromtimestamp(float(s_time) / 1000).strftime('%Y-%m-%d %H:%M:%S')

>print (d_time)

>2018-02-21 13:58:02
Answered By: Karthik

You can use datetime but must devide by 1000 to get the seconds
time = datetime.datetime.fromtimestamp(1519171200000/1000)

Answered By: test