当前
def current_time():
return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
def current_hour():
return datetime.now().strftime('%Y-%m-%d %H:00:00')
def current_day():
return datetime.now().strftime('%Y-%m-%d 00:00:00')
def current_week():
now = datetime.now()
return (now - timedelta(days=now.weekday())).strftime('%Y-%m-%d 00:00:00')
def current_month():
now = datetime.now()
return datetime(now.year, now.month, 1).strftime('%Y-%m-%d 00:00:00')
下一
def next_hour():
return (datetime.now() + timedelta(hours=1)).strftime('%Y-%m-%d %H:00:00')
def tomorrow():
return (datetime.now() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00')
def next_week():
now = datetime.now()
return (now - timedelta(days=now.weekday() - 7)).strftime('%Y-%m-%d 00:00:00')
def next_month():
now = datetime.now()
this_month_end = datetime(now.year, now.month, calendar.monthrange(now.year, now.month)[1])
next_month_start = this_month_end + timedelta(days=1)
return datetime(next_month_start.year, next_month_start.month, 1).strftime('%Y-%m-%d 00:00:00')
上一
def last_hour():
return (datetime.now() - timedelta(hours=1)).strftime('%Y-%m-%d %H:00:00')
def yesterday():
return (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d 00:00:00')
def last_week():
now = datetime.now()
return (now - timedelta(days=now.weekday() + 7)).strftime('%Y-%m-%d 00:00:00')
def last_month():
now = datetime.now()
last_month_end = datetime(now.year, now.month, 1) - timedelta(days=1)
return datetime(last_month_end.year, last_month_end.month, 1).strftime('%Y-%m-%d 00:00:00')