/**
* 获取当月或几个月后的月份
* @param nextMonth
* @return
*/
public static int addMonthValue(int nextMonth) {
LocalDate now = LocalDate.now();
if (nextMonth > 0) {
now = now.plus(nextMonth, ChronoUnit.MONTHS);
}
String nowStr = now.toString();
int firstPos = nowStr.indexOf('-', 0);
int secPost = nowStr.indexOf('-', firstPos + 1);
String substring = nowStr.substring(firstPos + 1, secPost);
return Integer.parseInt(substring);
}
/**
* 获取当年或几个月后的年份
* @param nextMonth
* @return
*/
public static int getYearByMonth(int nextMonth) {
LocalDate now = LocalDate.now();
if (nextMonth > 0) {
now = now.plus(nextMonth, ChronoUnit.MONTHS);
}
return now.getYear();
}
获取当月或者几个月的月份和年份--Java
最新推荐文章于 2023-07-30 16:31:18 发布