java怎样获得系统当前的年份?

2024-11-19 15:30:49
推荐回答(1个)
回答1:

方法一:

public static String getCurrentYear(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
Date date = new Date();        return sdf.format(date);

方法二:

public static String getSysYear() {
Calendar date = Calendar.getInstance();
String year = String.valueOf(date.get(Calendar.YEAR));        return year;
}