//本月的第一天0.00
public Date startTime() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
//将小时至0
calendar.set(Calendar.HOUR_OF_DAY, 0);
//将分钟至0
calendar.set(Calendar.MINUTE, 0);
//将秒至0
calendar.set(Calendar.SECOND, 0);
//将毫秒至0
calendar.set(Calendar.MILLISECOND, 0);
//获得当前月第一天
Date sdate = calendar.getTime();
return sdate;
}
//本月的最后一天23.59:59
public Date lastTime() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
//将小时至0
calendar.set(Calendar.HOUR_OF_DAY, 0);
//将分钟至0
calendar.set(Calendar.MINUTE, 0);
//将秒至0
calendar.set(Calendar.SECOND, 0);
//将毫秒至0
calendar.set(Calendar.MILLISECOND, 0);
//获得当前月第一天
Date sdate = calendar.getTime();
//将当前月加1;
calendar.add(Calendar.MONTH, 1);
//在当前月的下一月基础上减去1毫秒
calendar.add(Calendar.MILLISECOND, -1);
Date edate = calendar.getTime();
return edate;
}
java 本月的第一天0.00--本月的最后一天23.59:59
最新推荐文章于 2023-04-28 18:22:44 发布