Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python timestamp to js timestamp

Now I want to transfer timstamp() in Python into timstamp() in JS. But the problem is Python uses seconds, while JS uses milliseconds. How can I transfer Python's version into JS? For example:

  1. For Python

    python_stamp = int(time.mktime(time.gmtime()))
    

    then the output is

    python_stamp=1481269558
    
  2. But for JS:

    JS_timestamp = Date().getTime()
    

    then the output is

    JS_timestamp = 1481269558356
    

Do you know how to transfer Python's version into JS. By the way, please do not say python_stamp*1000, basically, it is not a solution I want to find.

like image 592
uniqueliu Avatar asked Sep 26 '26 13:09

uniqueliu


1 Answers

here are a couple of examples to get milliseconds

from datetime import datetime

print(int(datetime.now().strftime("%s%f")) / 1000)

example 2

from time import time

print(time())  # 1481253947.930211
print(int(time() * 1000))  # 1481253947930
like image 95
cmidi Avatar answered Sep 29 '26 02:09

cmidi