0

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

martineau
  • 119,623
  • 25
  • 170
  • 301
Kokosadk
  • 9
  • 3
  • Near-duplicate: [How to get the current time in Python](//stackoverflow.com/q/415511) – Aran-Fey Sep 21 '19 at 06:29
  • Possible duplicate of [How to get the current time in Python](https://stackoverflow.com/questions/415511/how-to-get-the-current-time-in-python) – GiftZwergrapper Sep 27 '19 at 13:29

2 Answers2

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
heyxh
  • 571
  • 7
  • 11
1

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.

Yogaraj
  • 322
  • 1
  • 4
  • 17
B. Ackerman
  • 161
  • 4