上面格式化有两种方式:
一是用DateFormat格式化:
Calendar calendar = Calendar.getInstance();
calendar.set(2015, 1, 1);
Date date = calendar.getTime();
DateFormat df = new SimpleDateFormat("EEE MMM dd yyyy", Locale.US);
System.out.println(df.format(date));
二是直接用String类的format方法:
Calendar calendar = Calendar.getInstance();
calendar.set(2015, 1, 1);
Date date = calendar.getTime();
System.out.println(String.format(Locale.US, "%ta", date));
System.out.println(String.format(Locale.US, "%tb", date));
版权声明:本文为博主原创文章,未经博主允许不得转载。