- public class Text9 {
- public static void main(String args[]) {
- getDay();
- }
- public static void getDay() {
- System.out.println("请按照格式输入:yyyy-MM-dd,请输入1970年以后的日期");
- Scanner sc = new Scanner(System.in);
- String str = sc.next();
- String strs[] = str.split("-");
- int year = Integer.parseInt(strs[0]);
- int mouth = Integer.parseInt(strs[1]);
- int day = Integer.parseInt(strs[2]);
- if (year < 1970 || mouth > 12 && mouth < 1 || day > 31 && day < 1) {
- System.out.println("输入日期不正确,请输入正确的日期");
- } else {
- int count = 0;
-
- for (int i = 1970; i < year; i++) {
- if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
- count = count + 366;
- continue;
- }
- count = count + 365;
- }
- System.out.println(count);
- for (int i = 1; i < mouth; i++) {
- if (mouth == 2) {
- if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
- count = count + 29;
- continue;
- }
- count = count + 28;
- continue;
- } else if (mouth == 4 || mouth == 6 || mouth == 9|| mouth == 11) {
- count = count + 30;
- continue;
- }
- count = count + 31;
- }
- System.out.println(count);
- count = count + day;
- switch (count % 7) {
- case 0:
- System.out.println("星期日");
- break;
- case 1:
- System.out.println("星期一");
- break;
- case 2:
- System.out.println("星期二");
- break;
- case 3:
- System.out.println("星期三");
- break;
- case 4:
- System.out.println("星期四");
- break;
- case 5:
- System.out.println("星期五");
- break;
- case 6:
- System.out.println("星期六");
- break;
- }
- }
- }
- }
复制代码 |