判断当天是否为月末
#!/usr/bin/env python3 # coding: utf-8 import datetime def last_day_of_month(any_day): """ 获取获得一个月中的最后一天 :param any_day: 任意日期 :return: string """ next_month = any_day.replace(day=28) + datetime.timedelta(days=4) # this will never fail return next_month - datetime.timedelta(days=next_month.day) # 当前日期 now = datetime.datetime.now().date() year,month,day = str(now).split("-") # 切割 # 年月日,转换为数字 year = int(year) month = int(month) day = int(day) # 获取这个月最后一天 last_day = last_day_of_month(datetime.date(year, month, day)) # 判断当前日期是否为月末 if str(now) == last_day: print('yes') else: print('no')