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());
}
![](https://i-blog.csdnimg.cn/blog_migrate/6067628f0cb7b5eb79bd010dfe4f9888.png)