与链接的问题一样,您需要使用
datetime.date对象而不是
datetime.datetime。要获得
datetime.datetime最终结果,可以使用
datetime.datetime.combine():
import datetimecurrent_time = datetime.datetime.now()# get friday, one week ago, at 16 o'clocklast_friday = (current_time.date() - datetime.timedelta(days=current_time.weekday()) + datetime.timedelta(days=4, weeks=-1))last_friday_at_16 = datetime.datetime.combine(last_friday, datetime.time(16))# if today is also friday, and after 16 o'clock, change to the current dateone_week = datetime.timedelta(weeks=1)if current_time - last_friday_at_16 >= one_week: last_friday_at_16 += one_week
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)