【发布时间】:2021-06-18 10:40:53
【问题描述】:
我需要减去两次,然后将它们之间的分钟数计算为最接近的分钟数。对于scheduled_time,它已变为字符串,我无法将其转换回时间
present_time = timezone.now().time()
print(present_time) //output is -> 10:36:01.847822
scheduled_time = datetime.strftime(test.scheduled_date_time, '%H:%M:%S') //output is -> 10:20:52 in string format
print(scheduled_time)
如何将两者相减并得到最接近的分钟数? :(
【问题讨论】:
-
你只是用strftime把datetime转换成str,为什么不能用那个时间实例ti substract呢。
-
@MohamedElKalioby,它不能,因为它已经变成了一个字符串
-
为什么设置为字符串,如果是字符串,可以使用‘strptime’函数将其转换回日期时间
-
@MohamedElKalioby,它不起作用。你能帮我用正确的方式编码吗?
-
test.scheduled_time 的类型是什么?
标签: python django django-models django-views django-templates