Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.