A
A
AlmazKayum2020-07-26 01:33:45
Python
AlmazKayum, 2020-07-26 01:33:45

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

3 answer(s)
H
hint000, 2020-07-26
@hint000

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

A
AlmazKayum, 2020-07-29
@AlmazKayum

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

S
Sergey Tikhonov, 2020-08-06
@tumbler

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 question

Ask a Question

731 491 924 answers to any question