Page 1 of 1

javascript time stamp to python date

Posted: Wed Nov 07, 2018 3:27 am
by devnull
I am getting a timestamp in miliseconds via json from javascript nodejs, I cannot change this format.

When I try and convert this to a python date, it is 30 years in the future:

Code: Select all

>>> import utime
>>> jsmsec = 1541559855359
>>> jssecs = int(jsmsec/1000)
>>> utime.localtime(jssecs)
(2048, 11, 6, 3, 3, 28, 4, 311)
However this is not as easy as just deducting 60 x 60 x 24 x 365 x 30 as there are leap years to consider.

Is there a simple way of converting a numeric javascript time in miliseconds to python date ?

Re: javascript time stamp to python date

Posted: Wed Nov 07, 2018 6:46 pm
by chuckbook
Use:

Code: Select all

UNIX_TIME = 946681200
mpy_ts = js_ts - UNIX_TIME*1000