Computer Science, asked by deepu1398, 10 months ago

How to compare Python DateTime with Javascript DateTime?

Answers

Answered by viveksoni1550
2

To get timestamp in JavaScript we use

var ts = new Date().getTime()

What is the proper way to convert it to a Python datetime so far I use the following code

>>> jsts = 1335205804950

>>> dt = datetime.datetime.fromtimestamp(jsts/1000)

>>> dt

datetime.datetime(2012, 4, 24, 0, 30, 4)

I divide timestamp by 1000 because I get error like

ValueError Traceback (most recent call last)

1 d = datetime.datetime.fromtimestamp(a)

ValueError: year is out of range

Sultan.

Similar questions