1

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!

1
  • 1
    @Sam: milliseconds, actually. Commented Mar 2, 2013 at 21:44

1 Answer 1

5

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)
Sign up to request clarification or add additional context in comments.

1 Comment

thanks so much Martijn. I spent over 5 hours already trying various things like playing around with this number in a javascript console, trying to use pyv8 to run javascript in my python program and running spynner. Your answer is just what i was looking for!!

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.