Answer the question
In order to leave comments, you need to log in
How to get 00:00 UTC at unixtime in Python?
How to get nearest unix time stamp 00:00 UTC in Python
For example,
if current UTC time is 25 July 22:33, how to get 26 July 00:00 unix time?
Answer the question
In order to leave comments, you need to log in
24:00 - 22:33 = 1:27 = 0:(1*60+27) = 0:87 = 0:0:(87*60) = 5220 seconds
take unixtime at the moment and add 5220 seconds, done
import time
def get_next_utc_unix_00_00():
current_date = time.strftime("%d %b %Y", time.gmtime(time.time() + 86400))
current_date += ' 00:00:00'
next_utc = int(time.mktime(time.strptime(current_date, '%d %b %Y %H:%M:%S')))
return next_utc
The datetime object has a replace method. We check that it's not midnight, replace the HMS with zeros and add timedelta(days=1) - that's tomorrow's midnight. Convert to unixtime - dt.timestamp()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question