本帖最后由 杨庆雷 于 2014-4-20 11:49 编辑
- public class DateDemo {
- public static void main(String[] args) throws ParseException {
- // TODO Auto-generated method stub
-
- getWeek();
-
- //通过给定时间
- Calendar ca = Calendar.getInstance();
- ca.set(2014, 4, 17);
- getWeek2(ca);
- }
-
- public static void getWeek(){
- String[] weeks = new String[]{"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
- Calendar cl = Calendar.getInstance();
- int weekIndex = cl.get(Calendar.DAY_OF_WEEK);
- System.out.println(weeks[weekIndex]);
- }
- public static void getWeek2(Calendar ca){
- String[] weeks = new String[]{"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
- int weekIndex = ca.get(Calendar.DAY_OF_WEEK);
- System.out.print(ca.get(Calendar.YEAR) + "年" +ca.get(Calendar.DAY_OF_MONTH)+"日 ");
- System.out.println(weeks[weekIndex]);
- }
- }
复制代码
|
|