我有一个 jdict 给我一个时间,我需要计算出那是多长时间前的时间,然后如果超过 x 时间就执行另一个动作。我想我会在几天内工作以改变现状。 jdict 时间给出为 (str) 'Wed Dec 7 10:42' - 所以我需要以某种方式转换它。
看完所有建议的答案后,我找到了很多解决方案。 我的问题现在真的归结为 - 我如何制作一个 str 'Wed Dec 7 10:42' - 一个可用的日期,以便我可以计算差异?
现在听起来很简单
from datetime import datetime
now = datetime.now()
print(now)
~~~ snip~~~
return jdict
print(f"{jdict['taken']}")
**Wed Dec 7 10:42
**
# variable = datetime(year, month, day, hour, minute, second)
start = datetime(2023,1,23,18,56,40)
print( start - now ) # this will print the difference of these 2 date and time