- Scanner scanner = new Scanner(System.in);
- // String source = "2014-08-03";
- String source = scanner.nextLine();
- String[] daysOfWeek = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(source));
- System.out.println(daysOfWeek[calendar.get(Calendar.DAY_OF_WEEK)-1]);
- System.out.println("第"+calendar.get(Calendar.DAY_OF_YEAR)+"天");
- scanner.close();
复制代码 |