如何比较 strftime 值 [英] how to compare strftime values
本文介绍了如何比较 strftime 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 strftime 创建了两个值,如下所示
I have two values created from strftime as below
TIMEFORMAT="%Y-%m-%d %H:%M:%S"
time1 = time.strftime(TIMEFORMAT)
time2 = time.strftime(TIMEFORMAT)
现在 time1 和 time 2 的值就像 "2013-11-22 04:03:56" "2013-11-22 01:03:56"
now the values of time1 and time 2 are like "2013-11-22 04:03:56" "2013-11-22 01:03:56"
值由其他脚本写入文件.我正在从文件中读取这些值,然后进行比较.
The values are written by other script to file. And I am reading these values back from file and then comparing.
我想比较这样的东西
if time1 > time2:
# do etc. etc.
如何比较这些时间?
推荐答案
是的,您可以比较它们.而且,是的,t1 >t2
.
Yes, you can compare them. And, yes, t1 > t2
.
In [1]: t1 = "2013-11-22 04:03:56"
In [2]: t2 = "2013-11-22 01:03:56"
In [3]: t1 > t2
Out[3]: True
In [4]: t1 < t2
Out[4]: False
In [5]: t1 == t2
Out[5]: False
这篇关于如何比较 strftime 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文