Java Code Examples for java.time.LocalTime#getHour()
The following examples show how to use
java.time.LocalTime#getHour() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKLocalDateTime.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@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); } }
Example 2
Source File: TCKLocalDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_minusHours_fromOne() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0)); LocalDate d = base.toLocalDate().plusDays(2); LocalTime t = LocalTime.of(4, 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); } }
Example 3
Source File: TCKLocalDateTime.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Test public void test_plusHours_fromOne() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0)); LocalDate d = base.toLocalDate().minusDays(3); LocalTime t = LocalTime.of(22, 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); } }
Example 4
Source File: TCKLocalDateTime.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@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); } }
Example 5
Source File: TCKLocalDateTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@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); } }
Example 6
Source File: TCKLocalDateTime.java From j2objc with Apache License 2.0 | 6 votes |
@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(String.valueOf(i), dt.toLocalDate(), d); assertEquals(dt.toLocalTime(), t); } }
Example 7
Source File: TCKLocalDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_plusHours_fromOne() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0)); LocalDate d = base.toLocalDate().minusDays(3); LocalTime t = LocalTime.of(22, 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); } }
Example 8
Source File: IslamicExpression.java From jstarcraft-core with Apache License 2.0 | 6 votes |
@Override public boolean isMatchDateTime(ZonedDateTime dateTime) { IslamicDate islamic = new IslamicDate(dateTime.toLocalDate()); int year = islamic.getYear(); int month = islamic.getMonth(); int day = islamic.getDay(); int size = IslamicDate.getDaySize(year, month); BitSet days = getDays(size); LocalTime time = dateTime.toLocalTime(); int hour = time.getHour(); int minute = time.getMinute(); int second = time.getSecond(); if (seconds.get(second) && minutes.get(minute) && hours.get(hour)) { if (days.get(day) && months.get(month) && years.get(year - IslamicDate.MINIMUM_YEAR)) { return true; } } return false; }
Example 9
Source File: TCKLocalDateTime.java From hottub with GNU General Public License v2.0 | 6 votes |
@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); } }
Example 10
Source File: TCKLocalDateTime.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_plusHours_fromOne() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0)); LocalDate d = base.toLocalDate().minusDays(3); LocalTime t = LocalTime.of(22, 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); } }
Example 11
Source File: TCKLocalDateTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Test public void test_minusHours_fromOne() { LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0)); LocalDate d = base.toLocalDate().plusDays(2); LocalTime t = LocalTime.of(4, 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); } }
Example 12
Source File: GameTimer.java From runelite with BSD 2-Clause "Simplified" License | 5 votes |
private static String formatTime(LocalTime time) { if (time.getHour() > 0) { return time.format(DateTimeFormatter.ofPattern("HH:mm")); } else if (time.getMinute() > 9) { return time.format(DateTimeFormatter.ofPattern("mm:ss")); } else { return time.format(DateTimeFormatter.ofPattern("m:ss")); } }
Example 13
Source File: TCKLocalizedPrinterParser.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") @Test(dataProvider="time") public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) { DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale); Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond()); String text = old.format(oldDate); DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale); String formatted = f.format(time); assertEquals(formatted, text); }
Example 14
Source File: CubaTimeFieldWrapper.java From cuba with Apache License 2.0 | 5 votes |
protected static AmPmLocalTime convertTo12hFormat(LocalTime time) { checkNotNull(time, "Unable to convert null value to 12h format"); int hour = time.getHour() == 0 || time.getHour() == 12 ? 12 : time.getHour() % 12; AmPm amPm = time.getHour() < 12 ? AmPm.AM : AmPm.PM; return new AmPmLocalTime(time.withHour(hour), amPm); }
Example 15
Source File: TCKLocalizedPrinterParser.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") @Test(dataProvider="time") public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) { DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale); Date oldDate = new Date(1970, 0, 0, time.getHour(), time.getMinute(), time.getSecond()); String text = old.format(oldDate); DateTimeFormatter f = builder.appendLocalized(null, timeStyle).toFormatter(locale); String formatted = f.format(time); assertEquals(formatted, text); }
Example 16
Source File: TimerControlTileSkin.java From OEE-Designer with MIT License | 4 votes |
private void drawTimeSections() { if (sectionMap.isEmpty()) return; ZonedDateTime time = tile.getTime(); DayOfWeek day = time.getDayOfWeek(); boolean isAM = time.get(ChronoField.AMPM_OF_DAY) == 0; double offset = 90; double angleStep = 360.0 / 60.0; boolean highlightSections = tile.isHighlightSections(); for (TimeSection section : sectionMap.keySet()) { LocalTime start = section.getStart(); LocalTime stop = section.getStop(); boolean isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0; boolean isStopAM = stop.get(ChronoField.AMPM_OF_DAY) == 0; boolean draw = isAM ? (isStartAM || isStopAM) : (!isStartAM || !isStopAM); if (!section.getDays().contains(day)) { draw = false; } if (!section.isActive()) { draw = false; } if (draw) { double sectionStartAngle = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180; double sectionAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep; if (start.getHour() > stop.getHour()) { sectionAngleExtend = (360.0 - Math.abs(sectionAngleExtend)); } Arc arc = sectionMap.get(section); arc.setCenterX(clockSize * 0.5); arc.setCenterY(clockSize * 0.5); arc.setRadiusX(clockSize * 0.45); arc.setRadiusY(clockSize * 0.45); arc.setStartAngle(-(offset + sectionStartAngle)); arc.setLength(-sectionAngleExtend); arc.setType(ArcType.OPEN); arc.setStrokeWidth(clockSize * 0.04); arc.setStrokeLineCap(StrokeLineCap.BUTT); arc.setFill(null); if (highlightSections) { arc.setStroke(section.contains(time.toLocalTime()) ? section.getHighlightColor() : section.getColor()); } else { arc.setStroke(section.getColor()); } } } }
Example 17
Source File: JavatimeTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static boolean isEqual(LocalTime lt, java.sql.Time t) { return lt.getHour() == t.getHours() && lt.getMinute() == t.getMinutes() && lt.getSecond() == t.getSeconds(); }
Example 18
Source File: ZoneRules.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Writes the state of the transition rule to the stream. * * @param rule the transition rule, not null * @param out the output stream, not null * @throws IOException if an error occurs */ static void writeRule(ZoneOffsetTransitionRule rule, DataOutput out) throws IOException { int month = rule.getMonth().getValue(); byte dom = (byte)rule.getDayOfMonthIndicator(); int dow = (rule.getDayOfWeek() == null ? -1 : rule.getDayOfWeek().getValue()); LocalTime time = rule.getLocalTime(); boolean timeEndOfDay = rule.isMidnightEndOfDay(); TimeDefinition timeDefinition = rule.getTimeDefinition(); ZoneOffset standardOffset = rule.getStandardOffset(); ZoneOffset offsetBefore = rule.getOffsetBefore(); ZoneOffset offsetAfter = rule.getOffsetAfter(); int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay()); int stdOffset = standardOffset.getTotalSeconds(); int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset; int afterDiff = offsetAfter.getTotalSeconds() - stdOffset; int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31); int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255); int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3); int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3); int dowByte = (dow == -1 ? 0 : dow); int b = (month << 28) + // 4 bytes ((dom + 32) << 22) + // 6 bytes (dowByte << 19) + // 3 bytes (timeByte << 14) + // 5 bytes (timeDefinition.ordinal() << 12) + // 2 bytes (stdOffsetByte << 4) + // 8 bytes (beforeByte << 2) + // 2 bytes afterByte; // 2 bytes out.writeInt(b); if (timeByte == 31) { out.writeInt(timeSecs); } if (stdOffsetByte == 255) { out.writeInt(stdOffset); } if (beforeByte == 3) { out.writeInt(offsetBefore.getTotalSeconds()); } if (afterByte == 3) { out.writeInt(offsetAfter.getTotalSeconds()); } }
Example 19
Source File: UseLocalTime.java From tutorials with MIT License | 4 votes |
int getHourFromLocalTime(LocalTime localTime) { return localTime.getHour(); }
Example 20
Source File: JavatimeTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private static boolean isEqual(LocalTime lt, java.sql.Time t) { return lt.getHour() == t.getHours() && lt.getMinute() == t.getMinutes() && lt.getSecond() == t.getSeconds(); }