[英]How to check if a timestamp is a whole hour
我正在构建一个python应用程序,我从各个时间序列中获取大量数据(范围从1分钟到1天)。 我只想存储完整时间(xx:00分钟)的时间(unix时间戳)。 我该如何构建此支票?
if timestamp % 3600 == 0: save the timestamp
是一个简单的if timestamp % 3600 == 0: save the timestamp
足够吗? 或者,还有更好的方法?
时间戳以秒为单位,因此时间模块3600应为零。
if timestamp % 3600 == 0:
# save the timestamp-value tuple
这就足够了,您不必创建一个datetime对象,并检查每个时间戳的分钟和秒。
from datetime import datetime
ts = 1415309268
cts = datetime.fromtimestamp(ts)
print(cts.minute==00)
如果你还要秒:
cts.minute==00 and cts.second==00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.