Java Code Examples for java.time.LocalDateTime#minusHours()
The following examples show how to use
java.time.LocalDateTime#minusHours() .
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 openjdk-8-source 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 2
Source File: TCKLocalDateTime.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Test public void test_minusHours_one() { LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); for (int i = 0; i < 50; i++) { t = t.minusHours(1); if (i % 24 == 0) { d = d.minusDays(1); } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24); } }
Example 3
Source File: TCKLocalDateTime.java From openjdk-jdk9 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 4
Source File: TCKLocalDateTime.java From j2objc with Apache License 2.0 | 6 votes |
@Test public void test_minusHours_one() { LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); for (int i = 0; i < 50; i++) { t = t.minusHours(1); if (i % 24 == 0) { d = d.minusDays(1); } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24); } }
Example 5
Source File: TCKLocalDateTime.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public void test_minusHours_one() { LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); for (int i = 0; i < 50; i++) { t = t.minusHours(1); if (i % 24 == 0) { d = d.minusDays(1); } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24); } }
Example 6
Source File: TCKLocalDateTime.java From openjdk-jdk8u-backup 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 7
Source File: TCKLocalDateTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Test public void test_minusHours_one() { LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); for (int i = 0; i < 50; i++) { t = t.minusHours(1); if (i % 24 == 0) { d = d.minusDays(1); } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24); } }
Example 8
Source File: TCKLocalDateTime.java From openjdk-jdk8u 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 9
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 10
Source File: TCKLocalDateTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_minusHours_one() { LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); for (int i = 0; i < 50; i++) { t = t.minusHours(1); if (i % 24 == 0) { d = d.minusDays(1); } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24); } }
Example 11
Source File: DurationTextTest.java From onetwo with Apache License 2.0 | 6 votes |
@Test public void testNiceDateText(){ DurationText dtext = DurationText.createSimpleChineseDurationText(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime date = LocalDateTime.now(); LocalDateTime date2 = date.minusSeconds(40); System.out.println("date: " + date.format(formatter)+", date2: " + date2.format(formatter)); // Duration duration = Duration.ofSeconds(date2.until(date, ChronoUnit.SECONDS)); String text = dtext.getText(date2, date); Assert.assertEquals("刚刚", text); date2 = date.minusMinutes(3); System.out.println("date: " + date.format(formatter)+", date2: " + date2.format(formatter)); text = dtext.getText(date2, date); Assert.assertEquals("3分钟前", text); date2 = date.minusHours(4); text = dtext.getText(date2, date); Assert.assertEquals("4小时前", text); date2 = date.minusDays(32); text = dtext.getText(date2, date); Assert.assertEquals("32天前", text); }
Example 12
Source File: TCKLocalDateTime.java From jdk8u60 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 13
Source File: TCKLocalDateTime.java From jdk8u-dev-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 14
Source File: TCKLocalDateTime.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Test public void test_minusHours_one() { LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); for (int i = 0; i < 50; i++) { t = t.minusHours(1); if (i % 24 == 0) { d = d.minusDays(1); } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24); } }
Example 15
Source File: TCKLocalDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_minusHours_one() { LocalDateTime t =TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); for (int i = 0; i < 50; i++) { t = t.minusHours(1); if (i % 24 == 0) { d = d.minusDays(1); } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (((-i + 23) % 24) + 24) % 24); } }
Example 16
Source File: TCKLocalDateTime.java From TencentKona-8 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 17
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 18
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 19
Source File: UseLocalDateTimeUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenLocalDateTime_whenManipulating_thenResultIsAsExpected() { LocalDateTime givenLocalDateTime = LocalDateTime.parse("2015-02-20T06:30:00"); LocalDateTime manipulatedLocalDateTime = givenLocalDateTime.plusDays(1); manipulatedLocalDateTime = manipulatedLocalDateTime.minusHours(2); assertThat(manipulatedLocalDateTime).isEqualTo(LocalDateTime.of(2015, Month.FEBRUARY, 21, 4, 30)); }
Example 20
Source File: ImportDateTime.java From axelor-open-suite with GNU Affero General Public License v3.0 | 5 votes |
public LocalDateTime updateHour(LocalDateTime datetime, String hour) { if (!Strings.isNullOrEmpty(hour)) { Matcher matcher = patternMonth.matcher(hour); if (matcher.find()) { Long hours = Long.parseLong(matcher.group()); if (hour.startsWith("+")) datetime = datetime.plusHours(hours); else if (hour.startsWith("-")) datetime = datetime.minusHours(hours); else datetime = datetime.withHour(hours.intValue()); } } return datetime; }