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


Java LocalTime.of方法代碼示例

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


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

示例1: test_plusHours_fromZero

import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void test_plusHours_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().minusDays(3);
    LocalTime t = LocalTime.of(21, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.plusHours(i);
        t = t.plusHours(1);

        if (t.getHour() == 0) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:TCKLocalDateTime.java

示例2: data_adjustInto

import java.time.LocalTime; //導入方法依賴的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

示例3: test_minusHours_fromZero

import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void test_minusHours_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().plusDays(2);
    LocalTime t = LocalTime.of(3, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.minusHours(i);
        t = t.minusHours(1);

        if (t.getHour() == 23) {
            d = d.minusDays(1);
        }

        assertEquals(dt.toLocalDate(), d, String.valueOf(i));
        assertEquals(dt.toLocalTime(), t);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:TCKLocalDateTime.java

示例4: test_get

import java.time.LocalTime; //導入方法依賴的package包/類
@Test(dataProvider="sampleTimes")
public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneOffset offset) {
    LocalDate localDate = LocalDate.of(y, o, d);
    LocalTime localTime = LocalTime.of(h, m, s, n);
    LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
    OffsetDateTime a = OffsetDateTime.of(localDateTime, offset);

    assertEquals(a.getYear(), localDate.getYear());
    assertEquals(a.getMonth(), localDate.getMonth());
    assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
    assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
    assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());

    assertEquals(a.getHour(), localDateTime.getHour());
    assertEquals(a.getMinute(), localDateTime.getMinute());
    assertEquals(a.getSecond(), localDateTime.getSecond());
    assertEquals(a.getNano(), localDateTime.getNano());

    assertEquals(a.toOffsetTime(), OffsetTime.of(localTime, offset));
    assertEquals(a.toString(), localDateTime.toString() + offset.toString());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:TCKOffsetDateTime.java

示例5: test_plusMinutes_fromZero

import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void test_plusMinutes_fromZero() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
    LocalDate d = base.toLocalDate().minusDays(1);
    LocalTime t = LocalTime.of(22, 49);

    for (int i = -70; i < 70; i++) {
        LocalDateTime dt = base.plusMinutes(i);
        t = t.plusMinutes(1);

        if (t.equals(LocalTime.MIDNIGHT)) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d, String.valueOf(i));
        assertEquals(dt.toLocalTime(), t, String.valueOf(i));
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:TCKLocalDateTime.java

示例6: factory_time_3ints_singletons

import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void factory_time_3ints_singletons() {
    for (int i = 0; i < 24; i++) {
        LocalTime test1 = LocalTime.of(i, 0, 0);
        LocalTime test2 = LocalTime.of(i, 0, 0);
        assertSame(test1, test2);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TestLocalTime.java

示例7: shouldUpdateRecurrenceSourceInterval

import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void shouldUpdateRecurrenceSourceInterval() {
    // given
    Interval oldInterval = recurrenceSourceEntry.getInterval();
    Interval newInterval = new Interval(LocalDate.now().plusDays(1),
            LocalTime.of(10, 00), LocalDate.now().plusDays(1),
            LocalTime.of(13, 45), ZoneId.of("UTC"));

    // when
    recurrence.setInterval(newInterval);

    // then
    assertThat(newInterval, is(not(equalTo(oldInterval))));
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:15,代碼來源:CalendarTest.java

示例8: localTimeRanges

import java.time.LocalTime; //導入方法依賴的package包/類
@DataProvider(name="LocalTimeRanges")
public Object[][] localTimeRanges() {
    return new Object[][] {
            { LocalTime.of(9, 0), LocalTime.of(13, 0), Duration.ofSeconds(1), false },
            { LocalTime.of(9, 0), LocalTime.of(13, 0), Duration.ofSeconds(5), false },
            { LocalTime.of(20, 0), LocalTime.of(13, 0), Duration.ofSeconds(1), false },
            { LocalTime.of(20, 0), LocalTime.of(13, 0), Duration.ofSeconds(7), false },
            { LocalTime.of(9, 0), LocalTime.of(13, 0), Duration.ofSeconds(1), true },
            { LocalTime.of(9, 0), LocalTime.of(13, 0), Duration.ofSeconds(5), true },
            { LocalTime.of(20, 0), LocalTime.of(13, 0), Duration.ofSeconds(1), true },
            { LocalTime.of(20, 0), LocalTime.of(13, 0), Duration.ofSeconds(7), true },
    };
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:14,代碼來源:RangeFilterTests.java

示例9: factory_time_4ints

import java.time.LocalTime; //導入方法依賴的package包/類
@Test
public void factory_time_4ints() {
    LocalTime test = LocalTime.of(12, 30, 40, 987654321);
    check(test, 12, 30, 40, 987654321);
    test = LocalTime.of(12, 0, 40, 987654321);
    check(test, 12, 0, 40, 987654321);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:TCKLocalTime.java

示例10: toLocalTime

import java.time.LocalTime; //導入方法依賴的package包/類
/**
 * Convert a {@link Date} value into a {@link LocalTime}, using default calendar.
 * @param date Date to convert (may be null)
 * @return Converted {@link LocalTime}, or <code>null</code> if given date was <code>null</code>
 */
public static LocalTime toLocalTime(Date date) {
	if (date != null) {
		final Calendar c = Calendar.getInstance();
		c.setTime(date);
		return LocalTime.of(c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND),
				(int) TimeUnit.MILLISECONDS.toNanos(c.get(Calendar.MILLISECOND)));
	}
	return null;
}
 
開發者ID:holon-platform,項目名稱:holon-core,代碼行數:15,代碼來源:ConversionUtils.java

示例11: data_query

import java.time.LocalTime; //導入方法依賴的package包/類
@DataProvider(name="query")
Object[][] data_query() {
    return new Object[][] {
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.chronology(), IsoChronology.INSTANCE},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.zoneId(), null},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.precision(), ChronoUnit.NANOS},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.zone(), OFFSET_PONE},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.offset(), OFFSET_PONE},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.localDate(), LocalDate.of(2008, 6, 30)},
            {TEST_2008_6_30_11_30_59_000000500, TemporalQueries.localTime(), LocalTime.of(11, 30, 59, 500)},
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:TCKOffsetDateTime.java

示例12: test_toString

import java.time.LocalTime; //導入方法依賴的package包/類
@Test(dataProvider="sampleToString")
public void test_toString(int h, int m, int s, int n, String expected) {
    LocalTime t = LocalTime.of(h, m, s, n);
    String str = t.toString();
    assertEquals(str, expected);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:TCKLocalTime.java

示例13: setup

import java.time.LocalTime; //導入方法依賴的package包/類
@Before
public void setup() {

    // Create shifts
    Shift shift0 = new Shift(0, DayOfWeek.MONDAY, LocalTime.of(16, 45), LocalTime.of(19, 45));
    Shift shift1 = new Shift(1, DayOfWeek.TUESDAY, LocalTime.of(18, 0), LocalTime.of(21, 0));
    Shift shift2 = new Shift(2, DayOfWeek.WEDNESDAY, LocalTime.of(19, 0), LocalTime.of(21, 0));
    Shift shift3 = new Shift(3, DayOfWeek.THURSDAY, LocalTime.of(18, 30), LocalTime.of(21, 30));
    Shift shift4 = new Shift(4, DayOfWeek.FRIDAY, LocalTime.of(17, 15), LocalTime.of(20, 45));
    this.shifts.add(shift0);
    this.shifts.add(shift1);
    this.shifts.add(shift2);
    this.shifts.add(shift3);
    this.shifts.add(shift4);

    // Required shifts for courses
    Set<Shift> shiftSet0 = new HashSet<>();
    shiftSet0.add(shift0);
    Set<Shift> shiftSet1 = new HashSet<>();
    shiftSet1.add(shift1);
    shiftSet1.add(shift4);
    Set<Shift> shiftSet2 = new HashSet<>();
    shiftSet2.add(shift1);
    shiftSet2.add(shift2);
    shiftSet2.add(shift3);
    Set<Shift> shiftSet3 = new HashSet<>();
    shiftSet3.add(shift0);
    shiftSet3.add(shift2);
    shiftSet3.add(shift3);
    shiftSet3.add(shift4);

    // Create courses
    Course course0 = new Course(0, "CS 301", new CourseRequirements(shiftSet1, 1, 3, CourseIntensity.MEDIUM, null, 0));
    Course course1 = new Course(1, "CS 302", new CourseRequirements(shiftSet2, 2, 2, CourseIntensity.HIGH, null, 0));
    Course course2 = new Course(2, "CS 577", new CourseRequirements(shiftSet0, 1, 2, CourseIntensity.LOW, null, 0));
    Course course3 = new Course(3, "EMA 201", new CourseRequirements(shiftSet3, 4, 4, CourseIntensity.HIGH, null, 0));
    Course course4 = new Course(4, "ECE 210", new CourseRequirements(shiftSet0, 1, 1, CourseIntensity.LOW, null, 0));
    this.courses.add(course0);
    this.courses.add(course1);
    this.courses.add(course2);
    this.courses.add(course3);
    this.courses.add(course4);
}
 
開發者ID:cocolocomoco21,項目名稱:ULCRS,代碼行數:44,代碼來源:TutorTest.java

示例14: factory_time_4ints_minuteTooHigh

import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void factory_time_4ints_minuteTooHigh() {
    LocalTime.of(0, 60, 0, 0);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKLocalTime.java

示例15: test_until_invalidType

import java.time.LocalTime; //導入方法依賴的package包/類
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    LocalTime start = LocalTime.of(11, 30);
    start.until(LocalDate.of(2010, 6, 30), SECONDS);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:TCKLocalTime.java


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