可以使用Java中的Calendar类来获取当前年份和下一年年份。具体实现如下:

import java.util.Calendar;

public class YearExample {
    public static void main(String[] args) {
        // 获取当前年份
        int currentYear = Calendar.getInstance().get(Calendar.YEAR);
        System.out.println("当前年份:" + currentYear);

        // 获取下一年年份
        int nextYear = currentYear + 1;
        System.out.println("下一年年份:" + nextYear);
    }
}

运行结果:

当前年份:2021
下一年年份:2022
java 获取当前年份和下一年年份

原文地址: https://www.cveoy.top/t/topic/hj0X 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录