[英]find day and time from the mentioned total seconds starting from beginning of the week - python
以下是从一周开始的总秒数。 仅供参考 - 一天 86400 秒。
590400
我想使用 python 编写一些逻辑和显示,例如 SUNDAY 08:00PM
目前尚不清楚您想从哪一周开始。 要么在某个地方选择一个固定的“星期一”,然后从那里选择 go(如下所示),要么计算本周的特定星期一,或者任何你的逻辑。 如果您使用 DST 处理时区,这一点很重要,因为并非每天都是 86400 秒长。
from datetime import datetime, timedelta
monday = datetime(2019, 9, 23)
ts = monday + timedelta(seconds=590400)
print(ts.strftime('%A %I:%M %p')) # Sunday 08:00 PM
from datetime import datetime
t = 590400
h = 590400%86400
#calculating week
y = int(590400/86400)
if y == 6:
print("Saturday")
res = str(int(h/3600)) + ':00'
d = datetime.strptime(res, "%H:%M")
print(d.strftime("%I:%M %p"))
周六 08:00 PM
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.