//获得每个月最后一天的日期
public static Date getLastDayOfMonth(Date sDate1) {
Calendar cDay1 = Calendar.getInstance();
cDay1.setTime(sDate1);
final int lastDay = cDay1.getActualMaximum(Calendar.DAY_OF_MONTH);
Date lastDate = cDay1.getTime();
lastDate.setDate(lastDay);
return lastDate;
}
/**
* 得到前一个月的年月日时分秒
*/
public static String getLastMonthTime(){
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH)+1;
int date = calendar.get(Calendar.DATE);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
return year+"-"+(month<10?"0"+month:month)+"-"+(date<10?"0"+date:date)+(hour<10?"0"+hour:hour)+":"+(minute<10?"0"+minute:minute)+":"+(second<10?"0"+second:second);
}
//外加本月最后一天最后一秒的日期
String aString=getNowTime("yyyy/MM/dd");
aString=aString+" 23:59:59";
System.out.println(getLastDayOfMonth(DateUtils.getUtilDateByString(aString, "yyyy/MM/dd HH:mm:ss")));
获取每个月的最后一天的当前日期以及前一个月的当前日期,外加23:59:59
最新推荐文章于 2022-09-20 09:41:37 发布