标签:
#当前一周 def week_get_now(self): import datetime d = datetime.datetime.now() dayscount = datetime.timedelta(days=d.isoweekday()) dayto = d sixdays = datetime.timedelta(days=6) dayfrom = dayto - sixdays date_from = datetime.datetime(dayfrom.year, dayfrom.month, dayfrom.day, 0, 0, 0) date_to = datetime.datetime(dayto.year, dayto.month, dayto.day, 23, 59, 59) return str(date_from), str(date_to) #上一周时间段 def week_get(self): import datetime d = datetime.datetime.now() dayscount = datetime.timedelta(days=d.isoweekday()) dayto = d - dayscount sixdays = datetime.timedelta(days=6) dayfrom = dayto - sixdays date_from = datetime.datetime(dayfrom.year, dayfrom.month, dayfrom.day, 0, 0, 0) date_to = datetime.datetime(dayto.year, dayto.month, dayto.day, 23, 59, 59) return str(date_from), str(date_to) #上个月时间段 def month_get(self): import datetime d = datetime.datetime.now() dayscount = datetime.timedelta(days=d.day) dayto = d - dayscount date_from = datetime.datetime(dayto.year, dayto.month, 1, 0, 0, 0) date_to = datetime.datetime(dayto.year, dayto.month, dayto.day, 23, 59, 59) return str(date_from), str(date_to)
标签:
原文地址:http://www.cnblogs.com/lzpblog/p/4380703.html