减去两个 datetime.time
我基本上需要获取实际时间(time1)并查看到 time2 需要多少小时和分钟。 这是一个倒计时,距离时间2还有多少时间。
我一直在做这个
def schedule_task():
exp_h = 23
exp_m = 5
now = datetime.datetime.now()
if len(str(exp_m))==1:
exp_m=str("0")+str(exp_m)
date_time_str = str(exp_h)+":"+str(exp_m)+":00"
exp_now = datetime.datetime.strptime(date_time_str,"%H:%M:%S").time()
fdate = datetime.datetime.now().strftime("%H:%M:%S")
locl_h = now.strftime("%H")
locl_m = now.strftime("%M")
remain = datetime.datetime.combine(now.today(), fdate.time()) - datetime.datetime.combine(now.today(), exp_now)
lbl_remaing.config(text="Request will be sent in "+str(remain), bg="darkgrey",fg="blue")
if locl_h.strip()==exp_h.strip() and locl_m.strip()==exp_m.strip():
print("run func")
else:
lbl_remaing.after(1000, schedule_task)
有这个错误
print("----> ",datetime.datetime.combine(now.today(), fdate.time())
- datetime.datetime.combine(now.today(), exp_now.time())) AttributeError: 'str' 对象没有属性 'time'
i basicly need to get actual time(time1) and see how many hours and minutos to time2.
Its a countdown, how many time untill time2.
I have been making this
def schedule_task():
exp_h = 23
exp_m = 5
now = datetime.datetime.now()
if len(str(exp_m))==1:
exp_m=str("0")+str(exp_m)
date_time_str = str(exp_h)+":"+str(exp_m)+":00"
exp_now = datetime.datetime.strptime(date_time_str,"%H:%M:%S").time()
fdate = datetime.datetime.now().strftime("%H:%M:%S")
locl_h = now.strftime("%H")
locl_m = now.strftime("%M")
remain = datetime.datetime.combine(now.today(), fdate.time()) - datetime.datetime.combine(now.today(), exp_now)
lbl_remaing.config(text="Request will be sent in "+str(remain), bg="darkgrey",fg="blue")
if locl_h.strip()==exp_h.strip() and locl_m.strip()==exp_m.strip():
print("run func")
else:
lbl_remaing.after(1000, schedule_task)
Having this error
print("----> ",datetime.datetime.combine(now.today(), fdate.time())
- datetime.datetime.combine(now.today(), exp_now.time())) AttributeError: 'str' object has no attribute 'time'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
知道了:
Got it: