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


Java LocalTime類代碼示例

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


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

示例1: registerConfigProducer

import java.time.LocalTime; //導入依賴的package包/類
public void registerConfigProducer(@Observes AfterBeanDiscovery abd, BeanManager bm) {
    // excludes type that are already produced by ConfigProducer
    Set<Class> types = injectionPoints.stream()
            .filter(ip -> ip.getType() instanceof Class
                    && ip.getType() != String.class
                    && ip.getType() != Boolean.class
                    && ip.getType() != Boolean.TYPE
                    && ip.getType() != Integer.class
                    && ip.getType() != Integer.TYPE
                    && ip.getType() != Long.class
                    && ip.getType() != Long.TYPE
                    && ip.getType() != Float.class
                    && ip.getType() != Float.TYPE
                    && ip.getType() != Double.class
                    && ip.getType() != Double.TYPE
                    && ip.getType() != Duration.class
                    && ip.getType() != LocalDate.class
                    && ip.getType() != LocalTime.class
                    && ip.getType() != LocalDateTime.class)
            .map(ip -> (Class) ip.getType())
            .collect(Collectors.toSet());
    types.forEach(type -> abd.addBean(new ConfigInjectionBean(bm, type)));
}
 
開發者ID:wildfly-extras,項目名稱:wildfly-microprofile-config,代碼行數:24,代碼來源:ConfigExtension.java

示例2: test_badWithAdjusterChrono

import java.time.LocalTime; //導入依賴的package包/類
@Test(dataProvider="calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalAdjuster adjuster = new FixedAdjuster(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.with(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException, "
                        + "required: " + cdt + ", supplied: " + cdt2);
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.with(adjuster);
            assertEquals(result, cdt2, "WithAdjuster failed to replace date");
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:TCKChronoLocalDateTime.java

示例3: run

import java.time.LocalTime; //導入依賴的package包/類
@Override
@SuppressWarnings("InfiniteLoopStatement")
public void run() {
    while (true) {
        Platform.runLater(() -> {
            calendarView.setToday(LocalDate.now());
            calendarView.setTime(LocalTime.now());
        });

        try {
            sleep(TEN_SECONDS);
        } catch (InterruptedException e) {
            // Do nothing
        }
    }
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:17,代碼來源:CalendarViewTimeUpdateThread.java

示例4: test_resolveMinuteOfDay

import java.time.LocalTime; //導入依賴的package包/類
@Test(dataProvider="resolveMinuteOfDay")
public void test_resolveMinuteOfDay(ResolverStyle style, long value, Integer expectedMinute, int expectedDays) {
    String str = Long.toString(value);
    DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(MINUTE_OF_DAY).toFormatter();

    if (expectedMinute != null) {
        TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
        assertEquals(accessor.query(TemporalQueries.localDate()), null);
        assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedMinute * 60));
        assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
    } else {
        try {
            f.withResolverStyle(style).parse(str);
            fail();
        } catch (DateTimeParseException ex) {
            // expected
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:TCKDateTimeParseResolver.java

示例5: main

import java.time.LocalTime; //導入依賴的package包/類
public static void main(String[] args) {
    // Hours, minutes
    LocalTime timeHrsMin = LocalTime.of(12, 12);
    // Hours, minutes and seconds
    LocalTime timeHrsMinSec = LocalTime.of(0, 12, 6);
    // Hours, minutes, seconds and nanoseconds
    LocalTime timeHrsMinSecNano = LocalTime.of(14, 7, 10, 998654578);

    // DateTimeException
    //LocalTime timeHrsMin1 = LocalTime.of(120, 12);// Runtime exception
    //LocalTime timeHrsMin2 = LocalTime.of(9986545781, 12);// Compilation error

    // To get the current time from the system clock, use the static method now()
    LocalTime date3 = LocalTime.now();

    // Parse a string to instantiate LocalTime by using its static method parse()
    LocalTime time = LocalTime.parse("15:08:23");


}
 
開發者ID:huby,項目名稱:java-se8-oca-study-guide,代碼行數:21,代碼來源:Main.java

示例6: test_badPlusTemporalUnitChrono

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

示例7: test_badTemporalFieldChrono

import java.time.LocalTime; //導入依賴的package包/類
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(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);
        TemporalField adjuster = new FixedTemporalField(czdt2);
        if (chrono != chrono2) {
            try {
                czdt.with(adjuster, 1);
                Assert.fail("TemporalField doWith() should have thrown a ClassCastException, " + czdt.getClass()
                        + " can not be cast to " + czdt2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoZonedDateTime<?> result = czdt.with(adjuster, 1);
            assertEquals(result, czdt2, "TemporalField doWith() failed to replace date");
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:TCKChronoZonedDateTime.java

示例8: test_WBY_isSupportedBy

import java.time.LocalTime; //導入依賴的package包/類
@Test(dataProvider = "fields")
public void test_WBY_isSupportedBy(TemporalField weekField, TemporalField yearField) {
    assertEquals(yearField.isSupportedBy(LocalTime.NOON), false);
    assertEquals(yearField.isSupportedBy(MonthDay.of(2, 1)), false);
    assertEquals(yearField.isSupportedBy(LocalDate.MIN), true);
    assertEquals(yearField.isSupportedBy(OffsetDateTime.MAX), true);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:TestIsoWeekFields.java

示例9: data_unitAndTemporal

import java.time.LocalTime; //導入依賴的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:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:36,代碼來源:TCKChronoUnit.java

示例10: exception

import java.time.LocalTime; //導入依賴的package包/類
/**
 * used for logging significant (unexpected) errors (level 1)
 * @param caller the java class from which the command is called
 * @param error the error
 */
public static void exception(Class caller, Throwable error)
{
    if(Main.getBotSettingsManager().getLogLevel() < 1) return;

    String now = LocalTime.now().truncatedTo(ChronoUnit.SECONDS).format(DateTimeFormatter.ISO_LOCAL_TIME);
    String content = "[" + now + "] " +
            ANSI_PURPLE + "[Excp]" + ANSI_RESET + " " +
            ANSI_PURPLE_BACKGROUND + ANSI_BLACK +
            "[" + caller.getSimpleName() + "]" +
            ANSI_RESET + " " + ANSI_PURPLE + error.getMessage() +
            ANSI_RESET;
    System.out.println(content);
    error.printStackTrace();
}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:20,代碼來源:Logging.java

示例11: factory_time_4ints_singletons

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

示例12: now_Clock_allSecsInDay

import java.time.LocalTime; //導入依賴的package包/類
@Test
public void now_Clock_allSecsInDay() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        LocalTime test = LocalTime.now(clock);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 8);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:13,代碼來源:TCKLocalTime.java

示例13: getZonedDateTimeAt

import java.time.LocalTime; //導入依賴的package包/類
public ZonedDateTime getZonedDateTimeAt(double x, double y) {
    Point2D location = getSkinnable().localToScreen(x, y);
    for (MonthDayView view : controlsMap.values()) {
        if (view.localToScreen(view.getLayoutBounds()).contains(location)) {
            return ZonedDateTime.of(view.getDate(), LocalTime.NOON, getSkinnable().getZoneId());
        }
    }

    return null;
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:11,代碼來源:MonthViewSkin.java

示例14: test_toNanoOfDay

import java.time.LocalTime; //導入依賴的package包/類
@Test
public void test_toNanoOfDay() {
    LocalTime t = LocalTime.of(0, 0);
    for (int i = 0; i < 1000000; i++) {
        assertEquals(t.toNanoOfDay(), i);
        t = t.plusNanos(1);
    }
    t = LocalTime.of(0, 0);
    for (int i = 1; i <= 1000000; i++) {
        t = t.minusNanos(1);
        assertEquals(t.toNanoOfDay(), 24 * 60 * 60 * 1000000000L - i);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:TCKLocalTime.java

示例15: updateFields

import java.time.LocalTime; //導入依賴的package包/類
private void updateFields() {
    updatingFields = true;

    TimeField timeField = getSkinnable();
    LocalTime localTime = timeField.getValue();
    if (localTime != null) {
        hourField.setText(Integer.toString(localTime.getHour()));
        minuteField.setText(Integer.toString(localTime.getMinute()));
    } else {
        hourField.setText("");
        minuteField.setText("");
    }

    updatingFields = false;
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:16,代碼來源:TimeFieldSkin.java


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