按日查询日期(星期日,星期一)

时间:2015-09-08 16:45:18

标签: java

我正在尝试制作一个程序,你插入日,月,年...而它说巫婆的一天是它(星期日,星期一......)我做的那个但是有时工作,有时不...试试你的帮助!!

(我只需要在java上不使用日期系统函数或类似的东西)

Scanner scan = new Scanner(System.in);  

System.out.println("Enter Today Day : ");
int day = scan.nextInt();
System.out.println("Enter Today Month : ");
int dayMonth = scan.nextInt();
System.out.println("Enter Today Year : ");
int year = scan.nextInt();

String[] days = {"Friday","Saturday", "Sunday","Monday", "Tuesday", "Wednesday", "Thursday","Friday" };
int howManyDays = (year-1916)*365 + dayMonth + day ;  
int whatDay = howManyDays%7;
System.out.println(days[whatDay]);

1 个答案:

答案 0 :(得分:0)

这是关于查找特定日期工作日的算法的问题,并且实际上并不是特定于Java。

参见维基百科:https://en.wikipedia.org/wiki/Julian_day#Calculation