In python time.time() returns the time in seconds since the epoch as a floating point number, but it seems the number is a bit short. If I run in JavaScript new Date().valueOf() I get 13 digits in length.
But if I run python time.time() I get a float with 10 digits and 6 after the decimal. Is time.time() not the correct method to use to get the same 13 digits as JavaScripts new Date().valueOf() method which says:
The
valueOf()method returns the primitive value of a Date object as a number data type, the number of milliseconds since midnight 01 January, 1970 UTC.
CodePudding user response:
The "correct" value of the number of seconds elapsed since 1/1/70 is the 10 digit number returned by Python.
new Date().valueOf()
Returns the value in milliseconds. If you want to get the number of seconds elapsed since 1/1/70, you need:
new Date().valueOf() / 1000;
new Date().valueOf() / 1000
# 1641855239.355
Math.round(new Date().valueOf() / 1000);
# 1641855239
time.time()
Python returns the number of seconds elapsed since 1/1/70 and adds precision after the decimal point.
>>> import time
>>> time.time()
1641855239.3550372
>>>
>>> round(time.time())
1641855239
