Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting date from Python to Javascript

I'm having difficulty working with dates in Python and Javascript.

>>> d = date(2004, 01, 01) >>> d datetime.date(2004, 1, 1) >>> time.mktime(d.timetuple()) 1072944000.0 

Then, in Javascript (data sent over Ajax):

>>> new Date(1072944000.0) Tue Jan 13 1970 02:02:24 GMT-0800 (PST) {} 

I'm confused. Shouldn't the Javascript date be the same as the one that I entered in Python? What am I doing wrong?

like image 919
Nick Heiner Avatar asked Feb 16 '11 21:02

Nick Heiner


1 Answers

Javascript's Date() takes milliseconds as an argument. Python's uses seconds. You have to multiply by 1,000.

like image 200
nmichaels Avatar answered Sep 20 '22 16:09

nmichaels