我正在做一个复合 if 语句来计算某个日期是否是夏令时,但是当我试图找到一种方法来计算日期是在 11 月的第一个星期日之前还是之后,我陷入了困境。有人可以帮助我吗?这是我现在的代码:
public class Lab5 {
/**
* Return true if the given date/time is daylight savings.
* Daylight savings time begins 2am the second Sunday of March and ends 2am the first Sunday of November.
*
* @param month - represents the month with 1 = January, 12 = December
* @param date - represents the day of the month, between 1 and 31
* @param day - represents the day of the week with 1 = Sunday, 7 = Saturday
* @param hour - represents the hour of the day with 0 = midnight, 12 = noon
*
* Precondition: the month is between 1 and 12, the date is between 1 and 31, the day is between 1 and 7
* and the hour is between 0 and 23.
*/
public static boolean isDayLightSavings (int month, int date, int day, int hour) {
if (month == 1 || month == 2 || month == 12)
return false;
else if (month == 11) {
if (day == 1 && hour < 2 && date < 8)
return true;
else
return false;
}
else
return true;
}
}
编辑:我相信我的问题还不够清楚。我知道如何找到十一月的第一个星期日
else if (month == 11) {
if (day == 1 && hour < 2 && date < 8)
我似乎无法做的是找出我的日期是在 11 月的第一个星期日之前还是之后。我需要使用 if 语句,而不是预加载的库、方法或类。