appleLover
appleLover

Reputation: 15691

Parsing Javascript Date

A website I am looking at has the following code.

var d = new Date(1362236400000);

This javascript date object somehow encodes the following HTML output,

"2/3/2013 10:00"

Could someone please explain this encoding? I need to make a python script that manipulates those javascript numbers to recreate the HTML output. Thanks!

Upvotes: 1

Views: 121

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121486

The value is the number of miliseconds since the epoch. In Python that could be handled with the datetime.datetime.fromtimestamp() constructor:

>>> import datetime
>>> datetime.datetime.fromtimestamp(1362236400000/1000)
datetime.datetime(2013, 3, 2, 16, 0)

Upvotes: 5

Related Questions