Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何对照时间值进行检查?_Python_Django_Time - Fatal编程技术网

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

我想知道给定的时间是上午还是下午。我不确定这是否是在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.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字段..太棒了。这比我想象的要简单得多谢谢,太好了。这比我想象的要简单得多非常感谢。