2

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.

2
  • 4
    JS timestamps are in milliseconds... Python timestamps are in seconds. What do you mean that multiplying by 1000 isn't a solution that you want to find? What's wrong with it? Commented Dec 9, 2016 at 2:59
  • 2
    "it is not a solution I want to find." That sucks, because that's the best cross-platform way to do it. Commented Dec 9, 2016 at 3:17

1 Answer 1

9

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.