python比较datatime.time和datetime.timedelta

时间:2018-07-02 13:23:50

标签: python datetime timedelta

我有一个小时,一分钟,一秒钟的时间

 serverTime = 'Jul 2, 2018 3:21:56 PM'
 serverTime = serverTime.strftime('%H:%M:%S')
 serverTime = datetime.strptime(serverTime, '%H:%M:%S').time()
 print(serverTime)
 >> 15:21:56
 print(type(serverTime))
 >> <class 'datetime.time'>

我有一个像这样的时间

openTimeFrom = timedelta(milliseconds=hours['fromT'] 
print(serverTime)
>> 08:00:00
print(type(openTimeFrom))
>> <class 'datetime.timedelta'>

我想比较openTimeFromserverTime来确定serverTime是否大于openTimeFrom,但是我什么时候做

if serverTime > openTimeFrom:

我遇到此错误

  

TypeError:“ datetime.time”和“ datetime.timedelta”实例之间不支持“>”

0 个答案:

没有答案