0

Is there any function in python similar to new Date().getTime() in javascript? I want to get timestamp like this: 1569046436.991

2

2 Answers 2

2

You can import the time module and use time.time().

In [1]: import time

In [2]: time.time()
Out[2]: 1569048420.49872

This gives you the Unix epoch time which is the same format that new Date().getTime() returns in JavaScript.

Sign up to request clarification or add additional context in comments.

Comments

2

You can either use datetime.timestamp()

from datetime import datetime
print(datetime.now().timestamp())
>> 1569054370.358652

or time.time()

import time
print(time.time())
>> 1569054370.359672

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.