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
  • 112,593
  • 23
  • 157
  • 280
Ziva
  • 2,785
  • 13
  • 43
  • 78

2 Answers2

5

Try this :

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

Use:

from datetime import datetime

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