public class Main {
public static void main(String[] args) {
System.out.println(calc(2018, 3, 28)); // 水曜日
System.out.println(calc(2018, 2, 28)); // 水曜日
System.out.println(calc(2018, 1, 28)); // 日曜日
}
public static String calc(
double y,
double m,
double d) {
double M = 0;
if (m < 3) {
M = m + 12;
y = y - 1;
} else {
M = m;
}
int C = (int) (y / 100);
int Y = (int) (y % 100);
double R = 0;
if (y >= 1582) {
R = (C / 4) - C - C;
} else if (y >= 4) {
R = 5 - C;
} else {
throw new IllegalArgumentException("year >= 4");
}
Double h = (d + ((26 * (M + 1)) / 10) + Y + (Y / 4) + R) % 7;
String[] weekday = new String[] {
"土",
"日",
"月",
"火",
"水",
"木",
"金"
};
return weekday[h.intValue()];
}
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
00