I am creating a python application where I get a lot of data from different time periods (from 1 minute to 1 day). I would only like to save time (unix timestamps) that are exactly for an entire hour (xx: 00 minutes). How to create this check?
Is simple enough enough if timestamp % 3600 == 0: save the timestamp? Or is there a better way?
if timestamp % 3600 == 0: save the timestamp
The timestamp is in seconds, so 3600 should be zero.
if timestamp % 3600 == 0: # save the timestamp-value tuple
This is enough, you do not need to make a datetime object and check the minutes and seconds for each timestamp you get.
datetime.fromtimestamp
from datetime import datetime ts = 1415309268 cts = datetime.fromtimestamp(ts) print(cts.minute==00)
:
cts.minute==00 and cts.second==00