1

How can I take the current time in seconds in Python? I was using calendar.timegm(time.gmtime()) but I'm not sure if this given value is in seconds?

martineau
  • 119,623
  • 25
  • 170
  • 301
Ziva
  • 3,181
  • 15
  • 48
  • 80

2 Answers2

6

Try this :

import time
print(round(time.time()))
Arbaz Siddiqui
  • 441
  • 2
  • 10
0

Use:

from datetime import datetime

sec = int(datetime.utcnow().total_seconds()) % 86400
Vaibhav Bajaj
  • 1,934
  • 16
  • 29