时间处理

1:时间相加减,获取7天前的年月日

 d = datetime.datetime.now()

 d2 = d - datetime.timedelta(days=7)
 dd=d2.date()

2:时间比大小

end_time = datetime.datetime.strptime(
                end_time, '%Y-%m-%d %H:%M:%S')

start_time = datetime.datetime.strptime(
                start_time, '%Y-%m-%d %H:%M:%S')

start_timess = datetime.datetime.strptime(t1, '%Y-%m-%d %H:%M:%S')

end_timess = datetime.datetime.strptime(t2, '%Y-%m-%d %H:%M:%S')

start_timess >= start_time and end_timess <= end_time

3:特殊时间处理“2015-12-7T16:00:00.000Z”

start_time = datetime.datetime.strptime(start_time, "%Y-%m-%dT%H:%M:%S.%fZ") + datetime.timedelta(hours=8)

你可能感兴趣的:(python)