本文整理汇总了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)));
}
示例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");
}
}
}
示例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
}
}
}
示例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
}
}
}
示例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");
}
示例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");
}
}
}
示例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");
}
}
}
示例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);
}
示例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},
};
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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;
}