python before_day 获取时间
import datetime def get_month_zone(before_day): today = datetime.date.today() day = today.day year = today.year month = today.month if day > before_day: last_day = today-datetime.timedelta(1) first_day = datetime.date(datetime.date.today().year,datetime.date.today().month,1) else: last_day = datetime.date(year,month,1)-datetime.timedelta(1) first_day = datetime.date(last_day.year,last_day.month,1) return [first_day, last_day] time_zone = get_month_zone(16) print('时间区间:{}-----{}'.format(time_zone[0].strftime("%Y-%m-%d"), time_zone[1].strftime(("%Y-%m-%d"))))