package com.minrisoft;
import java.lang.String;
import java.util.Scanner;
public class Riqi {
public static boolean leapYear(int y){
if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
return true;
else
return false;
}
public static void calcWeek(int a,int b,int c){
if(b == 1){
b = 13;
a =a - 1;
}
if(b ==12){
b = 14;
a = a - 1;
}
int h = (int) ((c + (26 * (b + 1) / 10) + (a % 100) + ((a % 100) / 4) + ((a / 100) / 4) + 5 * (a / 100)) % 7);
switch (h) {
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;
}
}
public static int countDay(int y, int m, int d){
int month_1[] ={ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int month_2[] ={ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int count = 0;
do {
count += 365;
if (leapYear(y) == true)
count += 1;
}while((--y)!= 0);
do{
if (leapYear(y) == true)
count += month_1[m-1];
else
count += month_2[m-1];
}while ((--m)!= 0);
count += d;
return count;
}
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
System.out.print("请输入日期(格式:yymmdd):");
String y_m_d_1 = sc.nextLine();
sc.close();
int x =Integer.parseInt(y_m_d_1.substring(0,4));
int y =Integer.parseInt(y_m_d_1.substring(4,6));
int z =Integer.parseInt(y_m_d_1.substring(6,8));
if (y >= 1 && y <= 12 && z >= 1 && z <= 31){
if (y == 4 || y == 6 || y == 9 || y == 11){
if (z > 30){
System.out.println("输入错误");
return;
}
}
if (y == 2){
if (leapYear(y) == true){
if (z > 29){
System.out.println("输入错误");
return;
}
}
else{
if (z > 28){
System.out.println("输入错误");
return;
}
}
}
}
else{
System.out.println("输入错误");
return;
}
System.out.println(x + "年" + y + "月" + z + "日:输入正确");
int year_1 = countDay(x,y,z);
int year_2 = countDay(2017,04,21);
calcWeek(x,y,z);
if (year_1 == year_2)
System.out.println("处于今天");
if (year_1 < year_2)
System.out.println("距离" + (year_2 - year_1) + "天");
if (year_1 > year_2){
System.out.println("距离" + (year_1 - year_2) + "天");
System.out.println(x + "年" + y + "月" + z + "日:没有出生");
}
else{
int n = 2017 - x;
if (y > 4 || (x != 2017 && y == 4 && z > 21))
n -= 1;
System.out.println("今年"+ n + "岁");
}
}
}
import java.lang.String;
import java.util.Scanner;
public class Riqi {
public static boolean leapYear(int y){
if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
return true;
else
return false;
}
public static void calcWeek(int a,int b,int c){
if(b == 1){
b = 13;
a =a - 1;
}
if(b ==12){
b = 14;
a = a - 1;
}
int h = (int) ((c + (26 * (b + 1) / 10) + (a % 100) + ((a % 100) / 4) + ((a / 100) / 4) + 5 * (a / 100)) % 7);
switch (h) {
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;
}
}
public static int countDay(int y, int m, int d){
int month_1[] ={ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int month_2[] ={ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int count = 0;
do {
count += 365;
if (leapYear(y) == true)
count += 1;
}while((--y)!= 0);
do{
if (leapYear(y) == true)
count += month_1[m-1];
else
count += month_2[m-1];
}while ((--m)!= 0);
count += d;
return count;
}
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
System.out.print("请输入日期(格式:yymmdd):");
String y_m_d_1 = sc.nextLine();
sc.close();
int x =Integer.parseInt(y_m_d_1.substring(0,4));
int y =Integer.parseInt(y_m_d_1.substring(4,6));
int z =Integer.parseInt(y_m_d_1.substring(6,8));
if (y >= 1 && y <= 12 && z >= 1 && z <= 31){
if (y == 4 || y == 6 || y == 9 || y == 11){
if (z > 30){
System.out.println("输入错误");
return;
}
}
if (y == 2){
if (leapYear(y) == true){
if (z > 29){
System.out.println("输入错误");
return;
}
}
else{
if (z > 28){
System.out.println("输入错误");
return;
}
}
}
}
else{
System.out.println("输入错误");
return;
}
System.out.println(x + "年" + y + "月" + z + "日:输入正确");
int year_1 = countDay(x,y,z);
int year_2 = countDay(2017,04,21);
calcWeek(x,y,z);
if (year_1 == year_2)
System.out.println("处于今天");
if (year_1 < year_2)
System.out.println("距离" + (year_2 - year_1) + "天");
if (year_1 > year_2){
System.out.println("距离" + (year_1 - year_2) + "天");
System.out.println(x + "年" + y + "月" + z + "日:没有出生");
}
else{
int n = 2017 - x;
if (y > 4 || (x != 2017 && y == 4 && z > 21))
n -= 1;
System.out.println("今年"+ n + "岁");
}
}
}