java基础篇 —— java创建对象有哪
489 2023-04-03 04:39:06
import datetimedef get_date_of_last_month(): """ 获取上月开始结束日期 :return: str,date tuple """ today = datetime.date.today() days_count = datetime.timedelta(today.day) end_date = today - days_count year_month = end_date.strftime("%Y-%m") begin_of_last_month = f"{year_month}-01" end_of_last_month = end_date.strftime("%Y-%m-%d") return begin_of_last_month, end_of_last_month
import datetimeimport calendardef get_date_of_last_month(): """ 获取上月开始结束日期 :return: str,date tuple """ today = datetime.date.today() today = datetime.date(2022, 1, 1) year = today.year month = today.month if month == 1: year -= 1 month = 12 else: month -= 1 begin_of_last_month = datetime.date(year, month, 1).strftime('%Y-%m-%d') _, day = calendar.monthrange(year, month) end_of_last_month = datetime.date(year, month, day).strftime('%Y-%m-%d') return begin_of_last_month, end_of_last_month
import datetimedef get_date_of_last_month(): """ 获取上月开始结束日期 :return: str,date tuple """ today = datetime.date.today() year = today.year month = today.month if month == 1: begin_of_last_month = datetime.date(year - 1, 12, 1).strftime('%Y-%m-%d') else: begin_of_last_month = datetime.date(year, month - 1, 1).strftime('%Y-%m-%d') end_of_last_month = (datetime.date(year, month, 1) + datetime.timedelta(-1)).strftime('%Y-%m-%d') return begin_of_last_month, end_of_last_month
import datetimeimport calendardef get_date_of_month(): """ 获取当月开始结束日期 :return: str,date tuple """ today = datetime.date.today() year = today.year month = today.month begin_of_month = datetime.date(year, month, 1).strftime('%Y-%m-%d') _, day = calendar.monthrange(year, month) end_of_month = datetime.date(year, month, day).strftime('%Y-%m-%d') return begin_of_month, end_of_month
import datetime import calendar def get_date_of_next_month(): """ 获取下月开始结束日期 :return: str,date tuple """ today = datetime.date.today() year = today.year month = today.month if month == 12: year += 1 month = 1 else: month += 1 begin_of_next_month = datetime.date(year, month, 1).strftime('%Y-%m-%d') _, day = calendar.monthrange(year, month) end_of_next_month = datetime.date(year, month, day).strftime('%Y-%m-%d') return begin_of_next_month, end_of_next_month