<span style="white-space:pre"> </span>//清明节
private boolean isTombSweeping(int year, int month, int day) {
if (month != 4) return false;
if (day != 4 && day != 5 && day != 6) return false;
int tempYear = (year % 10) + (((year / 10) % 10) * 10);
int tombSweepingDay = (int) ((tempYear * 0.2422 + 4.81) - (tempYear / 4));
if (tombSweepingDay == day) return true;
return false;
}
//母亲节和父亲节
private String getMotherOrFatherDay(int year, int month, int day) {
if (month != 5 && month != 6) return "";
if ((month == 5 && (day < 8 || day > 14)) || (month == 6 && (day < 15 || day > 21))) return "";
Calendar calendar = Calendar.getInstance();
calendar.set(year, month - 1, 1);
int weekDate = calendar.get(Calendar.DAY_OF_WEEK);
weekDate = (weekDate == 1) ? 7 : weekDate - 1;
switch (month) {
case 5:
if (day == 15 - weekDate) {
return "母亲节";
}
break;
case 6:
if (day == 22 - weekDate) {
return "父亲节";
}
break;
}
return "";
}
java 几个节日 代码计算
最新推荐文章于 2024-04-03 19:06:58 发布
本文介绍了如何使用Java计算清明节、母亲节和父亲节的代码实现。通过判断日期和月份,结合特定算法确定节日日期,如清明节根据年份计算具体日期,母亲节和父亲节则根据月份和星期计算。
摘要由CSDN通过智能技术生成