# 今日
import time
today_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# 昨天
import datetime
cur_date = datetime.datetime.now().date()
yester_day = cur_date - datetime.timedelta(days=1)
# 周
import datetime
def get_current_week():
monday, sunday = datetime.date.today(), datetime.date.today()
one_day = datetime.timedelta(days=1)
while monday.weekday() != 0:
monday -= one_day
while sunday.weekday() != 6:
sunday += one_day
return str(monday), str(sunday)
# 月
from datetime import datetime
currentYear = datetime.now().year # 年
currentMonth = datetime.now().month # 月
currentDay = datetime.now().day # 天
year_month = str(currentYear) + "-" + str(currentMonth) + "-" + "01 00:00:00"
year_month_day = str(currentYear) + "-" + str(currentMonth) + "-" + str(currentDay) + " 23:59:59"