你可以使用java.time.Year类来获取当前系统的自然年份,并往前推3年。以下是示例代码:

import java.time.Year;

public class Main {
    public static void main(String[] args) {
        Year currentYear = Year.now();
        Year threeYearsAgo = currentYear.minusYears(3);
        
        System.out.println("当前年份:" + currentYear);
        System.out.println("往前推3年:" + threeYearsAgo);
    }
}

输出结果会显示当前年份和往前推3年后的年份。请注意,必须使用Java 8或更高版本才能运行此代码。

当前系统的自然年份往前推3年 java8

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

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