我今天晚上刚刚写的,day14的作业。。。
public class Test_Calendar {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个日期字符串,如2015-10-20:");
String date = sc.nextLine();
String[] str = date.split("-");
int year = Integer.parseInt(str[0]);
int month = Integer.parseInt(str[1]);
int day = Integer.parseInt(str[2]);
Calendar c = Calendar.getInstance();
c.set(year, month - 1, day);
System.out.println(year + "年-" + month + "月-" + day + "日是"
+ getWeek(c.get(Calendar.DAY_OF_WEEK)) + ",是" + year + "年的第"
+ c.get(Calendar.DAY_OF_YEAR) + "天");
}
public static String getWeek(int week) {
String[] arr = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
return arr[week];
}
} |