public static void main(String[] args) {
System.out.println(getYear());
System.out.println(getMonth());
System.out.println(getDay());
}
/**
* 获取当前年份
* @return
*/
public static String getYear(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
return sdf.format(new Date());
}
/**
* 获取当前月份
* @return
*/
public static String getMonth(){
SimpleDateFormat sdf = new SimpleDateFormat("MM");
return sdf.format(new Date());
}
/**
* 获取当前天
* @return
*/
public static String getDay(){
SimpleDateFormat sdf = new SimpleDateFormat("dd");
return sdf.format(new Date());
}
获取当前日期的年、月、日
最新推荐文章于 2024-05-06 18:22:08 发布