-2

How do I get the current Unix timestamp in Python? I really want to know how many seconds have elapsed since January 1st, 1970.

CypherX
  • 6,127
  • 3
  • 16
  • 30
nmichaels
  • 47,648
  • 12
  • 99
  • 131
  • Your question isabout getting the unix timestamp - you can do this using datetime.now().timestamp() - see https://docs.python.org/3/library/datetime.html?highlight=re#datetime.datetime.timestamp - which is partof the dupes above. Or you can subtract datetime(1970,1,1,0,0,0) from datetime.now() and get its total_seconds() - wich is also described in the dupes. Still sure this is not a dupe? – Patrick Artner Oct 14 '19 at 20:39
  • 1
    @Patrick Artner The dupe I left up is actually real. It's just very disappointing that Googling for "seconds since epoch Python" gets you to a different answer of mine that's to an entirely different question. – nmichaels Oct 14 '19 at 20:47

1 Answers1

1
>>> import time
>>> time.time()
1571084862.598271

Convert it to an integer, if required, with

int(time.time())
nmichaels
  • 47,648
  • 12
  • 99
  • 131