Python 如何对照时间值进行检查?
我想知道给定的时间是上午还是下午。我不确定这是否是在python中创建时间对象并与之进行比较的正确方法。还是有更好的办法Python 如何对照时间值进行检查?,python,django,time,Python,Django,Time,我想知道给定的时间是上午还是下午。我不确定这是否是在python中创建时间对象并与之进行比较的正确方法。还是有更好的办法 def part_of_day_statistics(x): if x > time.strptime('6:00 am') and x < time.strptime('11:59 am'): return 'Morning' if x > time.strptime('12:00 pm') and x < time
def part_of_day_statistics(x):
if x > time.strptime('6:00 am') and x < time.strptime('11:59 am'):
return 'Morning'
if x > time.strptime('12:00 pm') and x < time.strptime('5:59 pm'):
return 'Afternoon'
Django是,其.hour属性范围为0到23:
def part_of_day_statistics(x):
if x.hour >= 6 and x.hour < 12:
return 'Morning'
if x.hour >= 12 and x.hour < 18:
return 'Afternoon'
Django是,其.hour属性范围为0到23:
def part_of_day_statistics(x):
if x.hour >= 6 and x.hour < 12:
return 'Morning'
if x.hour >= 12 and x.hour < 18:
return 'Afternoon'
大概x是一个unix时间戳秒数,从纪元开始?对不起,不是Django contact_time=models.timeieldah中的时间字段,那是datetime.time字段..大概x是一个unix时间戳秒数,从纪元开始?对不起,不是Django contact_time=models.timeieldah中的时间字段,那是datetime.time字段..太棒了。这比我想象的要简单得多谢谢,太好了。这比我想象的要简单得多非常感谢。