获取当前月的 下一个月1号
private static Date TimeTools(Date date) throws ParseException {
Calendar calendar = Calendar.getInstance();//日历对象
calendar.setTime(date);
int year = calendar.get(Calendar.YEAR); //获取年
int month = calendar.get(Calendar.MONTH) + 1; //获取月
int day = 1;//获取日
if (month==12){
month=1;
year = year+1;
}
String newDate = year +"-"+month +"-"+day;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date parse = sdf.parse(newDate);
return parse;
}

这段代码创建了一个日历对象,通过设置日期,获取当前月份的下一个月1号,并进行日期字符串的格式化。如果当前月份为12月,则年份会加1,然后返回解析后的日期对象。

被折叠的 条评论
为什么被折叠?



