當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDate.of方法代碼示例

本文整理匯總了Java中java.time.LocalDate.of方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.of方法的具體用法?Java LocalDate.of怎麽用?Java LocalDate.of使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.LocalDate的用法示例。


在下文中一共展示了LocalDate.of方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: data_adjustInto

import java.time.LocalDate; //導入方法依賴的package包/類
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(LocalTime.of(1, 1, 1, 100), ZoneOffset.UTC), OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MIN, OffsetTime.of(LocalTime.of(23 , 5), OFFSET_PONE), null},
            {OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MAX.toLocalTime(), ZoneOffset.ofHours(-18)), null},
            {OffsetTime.MIN, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MIN.toLocalTime(), ZoneOffset.ofHours(18)), null},


            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZONE_GAZA), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), ZONE_GAZA), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZoneOffset.UTC), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), OFFSET_PONE), null},

            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalTime.of(22, 3, 0), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null, null, NullPointerException.class},

    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:TCKOffsetTime.java

示例2: test_badPlusTemporalUnitChrono

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
        TemporalUnit adjuster = new FixedTemporalUnit(czdt2);
        if (chrono != chrono2) {
            try {
                czdt.plus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException, " + czdt
                        + " can not be cast to " + czdt2);
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoZonedDateTime<?> result = czdt.plus(1, adjuster);
            assertEquals(result, czdt2, "WithAdjuster failed to replace date");
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:TCKChronoZonedDateTime.java

示例3: data_resolveTwoToDate

import java.time.LocalDate; //導入方法依賴的package包/類
@DataProvider(name="resolveTwoToDate")
Object[][] data_resolveTwoToDate() {
    return new Object[][]{
            // merge
            {YEAR, 2012, DAY_OF_YEAR, 32, LocalDate.of(2012, 2, 1)},
            {YEAR_OF_ERA, 2012, DAY_OF_YEAR, 32, LocalDate.of(2012, 2, 1)},

            // merge
            {PROLEPTIC_MONTH, 2012 * 12 + (2 - 1), DAY_OF_MONTH, 25, LocalDate.of(2012, 2, 25)},
            {PROLEPTIC_MONTH, 2012 * 12 + (2 - 1), DAY_OF_YEAR, 56, LocalDate.of(2012, 2, 25)},

            // cross-check
            {EPOCH_DAY, 32, ERA, 1, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, -146097 * 5L, ERA, 0, LocalDate.of(1970 - (400 * 5), 1, 1)},
            {EPOCH_DAY, 32, YEAR, 1970, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, -146097 * 5L, YEAR, 1970 - (400 * 5), LocalDate.of(1970 - (400 * 5), 1, 1)},
            {EPOCH_DAY, 32, YEAR_OF_ERA, 1970, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, -146097 * 5L, YEAR_OF_ERA, 1 - (1970 - (400 * 5)), LocalDate.of(1970 - (400 * 5), 1, 1)},
            {EPOCH_DAY, 32, MONTH_OF_YEAR, 2, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, 32, DAY_OF_YEAR, 33, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, 32, DAY_OF_MONTH, 2, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, 32, DAY_OF_WEEK, 1, LocalDate.of(1970, 2, 2)},
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:TCKDateTimeParseResolver.java

示例4: data_unitAndTemporal

import java.time.LocalDate; //導入方法依賴的package包/類
@DataProvider(name="unitAndTemporal")
Object[][] data_unitAndTemporal() {
    return new Object[][] {
            {CENTURIES, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2100, 1, 10)},
            {DECADES, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2010, 1, 10)},
            {YEARS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2001, 1, 10)},
            {MONTHS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2000, 2, 10)},
            {WEEKS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2000, 1, 17)},
            {DAYS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2000, 1, 11)},

            {HALF_DAYS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(13, 2, 3, 400)},
            {HOURS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(2, 2, 3, 400)},
            {MINUTES, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 3, 3, 400)},
            {SECONDS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 4, 400)},
            {MICROS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 3, 1000 + 400)},
            {MILLIS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 3, 1000*1000 + 400)},
            {NANOS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 3, 1 + 400)},

            {CENTURIES, LocalTime.of(1, 2, 3, 400), false, 1, null},
            {DECADES, LocalTime.of(1, 2, 3, 400), false, 1, null},
            {YEARS, LocalTime.of(1, 2, 3, 400), false, 1, null},
            {MONTHS, LocalTime.of(1, 2, 3, 400), false, 1, null},
            {WEEKS, LocalTime.of(1, 2, 3, 400), false, 1, null},
            {DAYS, LocalTime.of(1, 2, 3, 400), false, 1, null},

            {HALF_DAYS, LocalDate.of(2000, 2, 29), false, 1, null},
            {HOURS, LocalDate.of(2000, 2, 29), false, 1, null},
            {MINUTES, LocalDate.of(2000, 2, 29), false, 1, null},
            {SECONDS, LocalDate.of(2000, 2, 29), false, 1, null},
            {MICROS, LocalDate.of(2000, 2, 29), false, 1, null},
            {MILLIS, LocalDate.of(2000, 2, 29), false, 1, null},
            {NANOS, LocalDate.of(2000, 2, 29), false, 1, null},

    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:TCKChronoUnit.java

示例5: provider_patternLocalDate

import java.time.LocalDate; //導入方法依賴的package包/類
@DataProvider(name="LocalWeekMonthYearPatterns")
Object[][] provider_patternLocalDate() {
    return new Object[][] {
        {"e W M y",  "1 1 1 2012", 0, 10, LocalDate.of(2012, 1, 1)},
        {"e W M y",  "1 2 1 2012", 0, 10, LocalDate.of(2012, 1, 8)},
        {"e W M y",  "2 2 1 2012", 0, 10, LocalDate.of(2012, 1, 9)},
        {"e W M y",  "3 2 1 2012", 0, 10, LocalDate.of(2012, 1, 10)},
        {"e W M y",  "1 3 1 2012", 0, 10, LocalDate.of(2012, 1, 15)},
        {"e W M y",  "2 3 1 2012", 0, 10, LocalDate.of(2012, 1, 16)},
        {"e W M y",  "6 2 1 2012", 0, 10, LocalDate.of(2012, 1, 13)},
        {"e W M y",  "6 2 7 2012", 0, 10, LocalDate.of(2012, 7, 13)},
        {"'Date: 'y-MM', day-of-week: 'e', week-of-month: 'W",
            "Date: 2012-07, day-of-week: 6, week-of-month: 3", 0, 47, LocalDate.of(2012, 7, 20)},
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:16,代碼來源:TCKLocalizedFieldParser.java

示例6: shouldNotBeEqualBecauseOfDifferentLocalDate

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void shouldNotBeEqualBecauseOfDifferentLocalDate() {
    // given
    Interval interval1 = new Interval(LocalDate.of(2017, 1, 14), LocalTime.of(10, 00), LocalDate.of(2017, 1, 15), LocalTime.of(23, 00));
    Interval interval2 = new Interval(LocalDate.of(2017, 1, 14), LocalTime.of(10, 00), LocalDate.of(2017, 1, 16), LocalTime.of(23, 00));

    // when
    boolean equal = interval1.equals(interval2);

    // then
    assertThat(equal, is(false));
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:13,代碼來源:IntervalTest.java

示例7: test_atDay_notLeapYear

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_atDay_notLeapYear() {
    Year test = Year.of(2007);
    LocalDate expected = LocalDate.of(2007, 1, 1);
    for (int i = 1; i <= 365; i++) {
        assertEquals(test.atDay(i), expected);
        expected = expected.plusDays(1);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:TCKYear.java

示例8: test_atTime_OffsetTime

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_atTime_OffsetTime() {
    LocalDate t = LocalDate.of(2008, 6, 30);
    assertEquals(t.atTime(OffsetTime.of(11, 30, 0, 0, OFFSET_PONE)), OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_PONE));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:TCKLocalDate.java

示例9: test_plusMonths_long_invalidTooLargeMaxAddMin

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void test_plusMonths_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.plusMonths(Long.MIN_VALUE);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:TCKLocalDate.java

示例10: test_atTime_int_int_int_int_secondTooSmall

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void test_atTime_int_int_int_int_secondTooSmall() {
    LocalDate t = LocalDate.of(2008, 6, 30);
    t.atTime(11, 30, -1, 50);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:6,代碼來源:TCKLocalDate.java

示例11: test_plusWeeks_maximum

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_plusWeeks_maximum() {
    LocalDate t = LocalDate.of(Year.MAX_VALUE, 12, 24).plusWeeks(1);
    LocalDate expected = LocalDate.of(Year.MAX_VALUE, 12, 31);
    assertEquals(t, expected);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:TCKLocalDate.java

示例12: test_toString

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="sampleToString")
public void test_toString(int y, int m, int d, String expected) {
    LocalDate t = LocalDate.of(y, m, d);
    String str = t.toString();
    assertEquals(str, expected);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:TCKLocalDate.java

示例13: factory_of_ints_dayTooLow

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_ints_dayTooLow() {
    LocalDate.of(2007, 1, 0);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:TCKLocalDate.java

示例14: readAll

import java.time.LocalDate; //導入方法依賴的package包/類
private static void readAll() throws IOException {
    final InternalEmojiDatabase collectorV1 = new InternalEmojiDatabase();
    readUnicodeV1(UNICODE_9_NAMES_LIST_TXT, collectorV1);
    readEmojiItemsV1(EMOJI_1_0_EMOJI_DATA_TXT, collectorV1);
    LocalDate releaseV1 = LocalDate.of(2015, 8, 4);
    writeCsv(TARGET_EMOJI_V1_CSV, releaseV1, collectorV1.getCsvRows());
    writeMarkdown(TARGET_EMOJI_V1_MD, "Emoji 1.0", releaseV1, collectorV1.getCsvRowsForEmojiOnly());

    final InternalEmojiDatabase collectorV2 = new InternalEmojiDatabase();
    readUnicodeV2(UNICODE_9_NAMES_LIST_TXT, collectorV2);
    readEmojiItemsV2(EMOJI_1_0_EMOJI_DATA_TXT, EMOJI_2_0_EMOJI_DATA_TXT, collectorV2);
    readEmojiSequencesV2(EMOJI_2_0_EMOJI_SEQUENCES_TXT, collectorV2);
    readEmojiSequencesV2(EMOJI_2_0_EMOJI_ZWJ_SEQUENCES_TXT, collectorV2);
    LocalDate releaseV2 = LocalDate.of(2015, 11, 11);
    writeCsv(TARGET_EMOJI_V2_CSV, releaseV2, collectorV2.getCsvRows());
    writeMarkdown(TARGET_EMOJI_V2_MD, "Emoji 2.0", releaseV2, collectorV2.getCsvRowsForEmojiOnly());

    final InternalEmojiDatabase collectorV3 = new InternalEmojiDatabase();
    readUnicodeV2(UNICODE_9_NAMES_LIST_TXT, collectorV3);
    readEmojiItemsV2(EMOJI_1_0_EMOJI_DATA_TXT, EMOJI_3_0_EMOJI_DATA_TXT, collectorV3);
    readEmojiSequencesV3(EMOJI_3_0_EMOJI_SEQUENCES_TXT, collectorV3);
    readEmojiSequencesV3(EMOJI_3_0_EMOJI_ZWJ_SEQUENCES_TXT, collectorV3);
    LocalDate releaseV3 = LocalDate.of(2016, 6, 2);
    writeCsv(TARGET_EMOJI_V3_CSV, releaseV3, collectorV3.getCsvRows());
    writeMarkdown(TARGET_EMOJI_V3_MD, "Emoji 3.0", releaseV3, collectorV3.getCsvRowsForEmojiOnly());

    final InternalEmojiDatabase collectorV4 = new InternalEmojiDatabase();
    readUnicodeV2(UNICODE_9_NAMES_LIST_TXT, collectorV4);
    readEmojiItemsV2(EMOJI_1_0_EMOJI_DATA_TXT, EMOJI_4_0_EMOJI_DATA_TXT, collectorV4);
    readEmojiSequencesV4(EMOJI_4_0_EMOJI_SEQUENCES_TXT, collectorV4);
    readEmojiSequencesV4(EMOJI_4_0_EMOJI_ZWJ_SEQUENCES_TXT, collectorV4);
    LocalDate releaseV4 = LocalDate.of(2016, 11, 14);
    writeCsv(TARGET_EMOJI_V4_CSV, releaseV4, collectorV4.getCsvRows());
    writeMarkdown(TARGET_EMOJI_V4_MD, "Emoji 4.0", releaseV4, collectorV4.getCsvRowsForEmojiOnly());

    final InternalEmojiDatabase collectorV5 = new InternalEmojiDatabase();
    readUnicodeV2(UNICODE_10_NAMES_LIST_TXT, collectorV5);
    readEmojiItemsV2(EMOJI_1_0_EMOJI_DATA_TXT, EMOJI_5_0_EMOJI_DATA_TXT, collectorV5);
    readEmojiSequencesV4(EMOJI_5_0_EMOJI_SEQUENCES_TXT, collectorV5);
    readEmojiSequencesV4(EMOJI_5_0_EMOJI_ZWJ_SEQUENCES_TXT, collectorV5);
    LocalDate releaseV5 = LocalDate.of(2017, 3, 27);
    writeCsv(TARGET_EMOJI_V5_CSV, releaseV5, collectorV5.getCsvRows());
    writeMarkdown(TARGET_EMOJI_V5_MD, "Emoji 5.0", releaseV5, collectorV5.getCsvRowsForEmojiOnly());
}
 
開發者ID:voho,項目名稱:emojava,代碼行數:45,代碼來源:Generator.java

示例15: date

import java.time.LocalDate; //導入方法依賴的package包/類
private LocalDate date(int year, int month, int day) {
    return LocalDate.of(year, month, day);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:4,代碼來源:TCKLocalDate.java


注:本文中的java.time.LocalDate.of方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。