Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  145] [ 1]  / answers: 1 / hits: 29126  / 14 Years ago, wed, february 16, 2011, 12:00:00

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?


More From » python

 Answers
32

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


[#93709] Monday, February 14, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaden

Total Points: 709
Total Questions: 91
Total Answers: 91

Location: Maldives
Member since Sat, Jan 29, 2022
2 Years ago
;