本文整理匯總了Java中java.time.LocalDate.withDayOfYear方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.withDayOfYear方法的具體用法?Java LocalDate.withDayOfYear怎麽用?Java LocalDate.withDayOfYear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.withDayOfYear方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test_weekOfYearField
import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_weekOfYearField(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate day = LocalDate.of(2012, 12, 31); // Known to be ISO Monday
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField woyField = week.weekOfYear();
for (int i = 1; i <= 15; i++) {
int actualDOW = day.get(dowField);
int actualWOY = day.get(woyField);
// Verify that the combination of day of week and week of month can be used
// to reconstruct the same date.
LocalDate day1 = day.withDayOfYear(1);
int offset = - (day1.get(dowField) - 1);
int week1 = day1.get(woyField);
if (week1 == 0) {
// week of the 1st is partial; start with first full week
offset += 7;
}
offset += actualDOW - 1;
offset += (actualWOY - 1) * 7;
LocalDate result = day1.plusDays(offset);
assertEquals(result, day, "Incorrect dayOfWeek or weekOfYear "
+ String.format("%s, ISO Dow: %s, offset: %s, actualDOW: %s, actualWOM: %s, expected: %s, result: %s%n",
week, day.getDayOfWeek(), offset, actualDOW, actualWOY, day, result));
day = day.plusDays(1);
}
}