Skip to content

Instantly share code, notes, and snippets.

@maskaravivek
Created May 20, 2020 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maskaravivek/877a7ac8a6844f23d42ba824dc146f45 to your computer and use it in GitHub Desktop.
Save maskaravivek/877a7ac8a6844f23d42ba824dc146f45 to your computer and use it in GitHub Desktop.
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