Created
May 20, 2020 09:07
-
-
Save maskaravivek/877a7ac8a6844f23d42ba824dc146f45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String dayOfTheWeek(int day, int month, int year) { | |
String[] days = new String[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; | |
int k = day; | |
int m = month < 3 ? month + 10 : month - 2; | |
int d = month < 3 ? (year % 100) - 1 : (year % 100); | |
int c = year / 100; | |
double f = k + Math.floor((13.0 * m - 1.0) / 5.0) + d + Math.floor(d / 4.0) + Math.floor(c / 4.0) - 2.0 * c; | |
int rem = (int) f % 7; | |
if (rem < 0) { | |
rem = 7 + rem; | |
} | |
return days[rem]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment