当前位置: 首页>>代码示例>>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;未经允许,请勿转载。