先说一下,养成良好的风格,一行代码尽量简短,并且保证一行代码只做一件事
DAY_OF_WEEK: 指一个星期中的某天。所以他会受到 第一天是星期几的影响。
有些地区以星期日作为一周的第一天,而有些地区以星期一作为一周的第一天,这2种情况是需要区分的。
下面是我改好的代码
- import java.util.*;
- public class Test
- {
- public static void main(String[] args)
- {
- String [] Months=new String[]{"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
- String [] Weeks=new String[]{"","日","一","二","三","四","五","六"};
- Calendar c=Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00")); //获取东八区时间
- System.out.print(c.get(Calendar.YEAR)+"年");
- System.out.print(Months[c.get(Calendar.MONTH)]);
- System.out.print(c.get(Calendar.DAY_OF_MONTH)+"日");
- System.out.print("星期"+Weeks[c.get(Calendar.DAY_OF_WEEK)]);
- }
- }
复制代码 |