本文整理匯總了Java中java.time.LocalDate.isLeapYear方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.isLeapYear方法的具體用法?Java LocalDate.isLeapYear怎麽用?Java LocalDate.isLeapYear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.isLeapYear方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getWeek
import java.time.LocalDate; //導入方法依賴的package包/類
private static int getWeek(LocalDate date) {
int dow0 = date.getDayOfWeek().ordinal();
int doy0 = date.getDayOfYear() - 1;
int doyThu0 = doy0 + (3 - dow0); // adjust to mid-week Thursday (which is 3 indexed from zero)
int alignedWeek = doyThu0 / 7;
int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
int firstMonDoy0 = firstThuDoy0 - 3;
if (firstMonDoy0 < -3) {
firstMonDoy0 += 7;
}
if (doy0 < firstMonDoy0) {
return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
}
int week = ((doy0 - firstMonDoy0) / 7) + 1;
if (week == 53) {
if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
week = 1;
}
}
return week;
}
示例2: getWeek
import java.time.LocalDate; //導入方法依賴的package包/類
private static int getWeek(LocalDate date) {
int dow0 = date.getDayOfWeek().ordinal();
int doy0 = date.getDayOfYear() - 1;
int doyThu0 = doy0 + (3 - dow0); // adjust to mid-week Thursday (which is 3 indexed from zero)
int alignedWeek = doyThu0 / 7;
int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
int firstMonDoy0 = firstThuDoy0 - 3;
if (firstMonDoy0 < -3) {
firstMonDoy0 += 7;
}
if (doy0 < firstMonDoy0) {
return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
}
int week = ((doy0 - firstMonDoy0) / 7) + 1;
if (week == 53) {
if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
week = 1;
}
}
return week;
}
示例3: getWeekRange
import java.time.LocalDate; //導入方法依賴的package包/類
private static int getWeekRange(int wby) {
LocalDate date = LocalDate.of(wby, 1, 1);
// 53 weeks if standard year starts on Thursday, or Wed in a leap year
if (date.getDayOfWeek() == THURSDAY || (date.getDayOfWeek() == WEDNESDAY && date.isLeapYear())) {
return 53;
}
return 52;
}
示例4: getWeekRange
import java.time.LocalDate; //導入方法依賴的package包/類
private static DateTimeValueRange getWeekRange(LocalDate date) {
int wby = getWeekBasedYear(date);
date = date.withDayOfYear(1).withYear(wby);
// 53 weeks if standard year starts on Thursday, or Wed in a leap year
if (date.getDayOfWeek() == THURSDAY || (date.getDayOfWeek() == WEDNESDAY && date.isLeapYear())) {
return DateTimeValueRange.of(1, 53);
}
return DateTimeValueRange.of(1, 52);
}
示例5: test_loop
import java.time.LocalDate; //導入方法依賴的package包/類
public void test_loop() {
// loop round at least one 400 year cycle, including before 1970
LocalDate date = LocalDate.of(1960, 1, 5); // Tuseday of week 1 1960
int year = 1960;
int wby = 1960;
int weekLen = 52;
int week = 1;
while (date.getYear() < 2400) {
DayOfWeek loopDow = date.getDayOfWeek();
if (date.getYear() != year) {
year = date.getYear();
}
if (loopDow == MONDAY) {
week++;
if ((week == 53 && weekLen == 52) || week == 54) {
week = 1;
LocalDate firstDayOfWeekBasedYear = date.plusDays(14).withDayOfYear(1);
DayOfWeek firstDay = firstDayOfWeekBasedYear.getDayOfWeek();
weekLen = (firstDay == THURSDAY || (firstDay == WEDNESDAY && firstDayOfWeekBasedYear.isLeapYear()) ? 53 : 52);
wby++;
}
}
assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.rangeRefinedBy(date), ValueRange.of(1, weekLen), "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(IsoFields.WEEK_OF_WEEK_BASED_YEAR.getFrom(date), week, "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(date.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR), week, "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(IsoFields.WEEK_BASED_YEAR.getFrom(date), wby, "Failed on " + date + " " + date.getDayOfWeek());
assertEquals(date.get(IsoFields.WEEK_BASED_YEAR), wby, "Failed on " + date + " " + date.getDayOfWeek());
date = date.plusDays(1);
}
}