2

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?

2
  • Possible duplicate of How to get current time in Python Commented Jul 27, 2016 at 7:34
  • 1
    Try time module. import time; time.time() Commented Jul 27, 2016 at 7:57

2 Answers 2

7

Try this :

import time print(round(time.time())) 
Sign up to request clarification or add additional context in comments.

1 Comment

also int(time.time()) if you don't want a float
0

Use:

from datetime import datetime sec = int(datetime.utcnow().total_seconds()) % 86400 

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.