判断今天是不是本月的最后一天
java 版本
public void lastDayOfThisMonth(){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd");
Date date = new Date();
int today = Integer.parseInt(simpleDateFormat.format(date));
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int actualMaximum = calendar.getActualMaximum(Calendar.DATE);
String result = today == actualMaximum ? "today is the last day of this month" : "today is not the last day of this month";
System.out.println(result);
}
python 版本
def func():
year = int(time.strftime("%Y"))
month = int(time.strftime("%m"))
today = int(time.strftime("%d"))
last_day = calendar.monthrange(year, month)[1]
result = "today is the last day of this month" if (today == last_day) else "today is not the last day of this month"
print(result)