I want to create a script that outputs the amount of time remaining (as "X hours, Y minutes, Z seconds remaining") until 27th August 9 AM (in IST).
我想创建一个脚本,输出剩余的时间(“X小时,Y分钟,Z秒剩余”),直到8月27日上午9点(在IST)。
This is what I tried:
这是我试过的:
import datetime
delta = datetime.datetime(2015, 8, 27) - datetime.datetime.now()
total_seconds = delta.total_seconds()
s = int(total_seconds)
print s
This prints 4439
, which is the wrong answer. I'm guessing it's a timezone issue. My timezone is Asia/Kolkata
and the correct answer should be 36720
.
这打印4439,这是错误的答案。我猜它是时区问题。我的时区是亚洲/加尔各答,正确答案应该是36720。
How can this be done?
如何才能做到这一点?
1 个解决方案
#1
0
Try this instead, I suspect the int() messes with the total_seconds object.
试试这个,我怀疑int()与total_seconds对象混淆。
import datetime
delta = datetime.datetime(2015, 8, 27) - datetime.datetime.now()
total_seconds = (delta).total_seconds()
print total_seconds
#1
0
Try this instead, I suspect the int() messes with the total_seconds object.
试试这个,我怀疑int()与total_seconds对象混淆。
import datetime
delta = datetime.datetime(2015, 8, 27) - datetime.datetime.now()
total_seconds = (delta).total_seconds()
print total_seconds