📄 printformatdate.java
字号:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class PrintFormatDate {
public static void main(String[] args) {
Calendar gc =Calendar.getInstance();
String time=
gc.get(Calendar.YEAR) + "-"
+ (gc.get(Calendar.MONTH) + 1) + "-"
+ gc.get(Calendar.DAY_OF_MONTH);
SimpleDateFormat s=new SimpleDateFormat("yyyy年MM月dd日");//2007年12月21日
SimpleDateFormat s2=new SimpleDateFormat("yyyy-MM-dd");//2007-12-21
Object d=null;//为什么d为Object就报错
try {
d=s2.parse(time);
System.out.println(s.format(d));//2007年12月18日
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -