Java Code Examples for java.time.ZonedDateTime#withHour()
The following examples show how to use
java.time.ZonedDateTime#withHour() .
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: TimeFilterTest.java From logging-log4j2 with Apache License 2.0 | 6 votes |
@Test public void fallBack() { final TimeFilter filter = new TimeFilter(LocalTime.of(1,0), LocalTime.of(2,0), ZoneId.of("America/Los_Angeles"), null, null, LocalDate.of(2020, 11, 1)); filter.start(); assertTrue(filter.isStarted()); ZonedDateTime date = ZonedDateTime.of(2020, 11, 1, 1, 6, 30, 0, ZoneId.of("America/Los_Angeles")).withEarlierOffsetAtOverlap(); CLOCKTIME = date.toInstant().toEpochMilli(); LogEvent event = Log4jLogEvent.newBuilder().setTimeMillis(CLOCKTIME).build(); assertSame("Time " + CLOCKTIME + " is not within range: " + filter.toString(), Filter.Result.NEUTRAL, filter.filter(event)); date = ZonedDateTime.of(2020, 11, 1, 1, 6, 30, 0, ZoneId.of("America/Los_Angeles")).withLaterOffsetAtOverlap(); CLOCKTIME = date.toInstant().toEpochMilli(); event = Log4jLogEvent.newBuilder().setTimeMillis(CLOCKTIME).build(); assertSame("Time " + CLOCKTIME + " is within range: " + filter.toString(), Filter.Result.DENY, filter.filter(event)); date = date.plusDays(1).withHour(1).withMinute(30); CLOCKTIME = date.toInstant().toEpochMilli(); event = Log4jLogEvent.newBuilder().setTimeMillis(CLOCKTIME).build(); assertSame("Time " + CLOCKTIME + " is not within range: " + filter.toString(), Filter.Result.NEUTRAL, filter.filter(event)); date = date.withHour(4); CLOCKTIME = date.toInstant().toEpochMilli(); event = Log4jLogEvent.newBuilder().setTimeMillis(CLOCKTIME).build(); assertSame("Time " + CLOCKTIME + " is within range: " + filter.toString(), Filter.Result.DENY, filter.filter(event)); }
Example 2
Source File: TimeUtil.java From game-server with MIT License | 5 votes |
public static long offsetCurrentTimeMillis(int offsetDays, int hour, int minute, int secord) { ZonedDateTime ldt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(currentTimeMillis()), ZoneId.systemDefault()); if (offsetDays > 0) { ldt = ldt.plusDays(offsetDays); } else if (offsetDays < 0) { ldt = ldt.minusDays(offsetDays); } ldt = ldt.withHour(hour); ldt = ldt.withMinute(minute); ldt = ldt.withSecond(secord); return ldt.toEpochSecond() * 1000; }
Example 3
Source File: TCKZonedDateTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_normal() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(15); assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withHour(15), ZONE_0100)); }
Example 4
Source File: TCKZonedDateTime.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_noChange() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(11); assertEquals(test, base); }
Example 5
Source File: TCKZonedDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_normal() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(15); assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withHour(15), ZONE_0100)); }
Example 6
Source File: TCKZonedDateTime.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_normal() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(15); assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withHour(15), ZONE_0100)); }
Example 7
Source File: TCKZonedDateTime.java From j2objc with Apache License 2.0 | 4 votes |
@Test public void test_withHour_normal() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(15); assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withHour(15), ZONE_0100)); }
Example 8
Source File: TCKZonedDateTime.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_noChange() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(11); assertEquals(test, base); }
Example 9
Source File: TCKZonedDateTime.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_normal() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(15); assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withHour(15), ZONE_0100)); }
Example 10
Source File: TCKZonedDateTime.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_noChange() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(11); assertEquals(test, base); }
Example 11
Source File: TCKZonedDateTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_noChange() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(11); assertEquals(test, base); }
Example 12
Source File: ZonedDateTimeAxis.java From constellation with Apache License 2.0 | 4 votes |
/** * Makes datetimes even, in the sense of that years always begin in January, * months always begin on the 1st and days always at midnight. * * @param dateTimes The list of dates. * @return The new list of dates. */ private List<ZonedDateTime> makeDateTimesEven(final List<ZonedDateTime> dateTimes) { // if the dates contain more dates than just the lower and upper bounds, make the dates in between even. if (dateTimes.size() > 2) { List<ZonedDateTime> evenDateTimes = new ArrayList<>(); // for each interval, modify the date slightly by a few millis, to make sure they are different days. // this is because Axis stores each value and won't update the tick labels, if the value is already known. // this happens if you display days and then add a date many years in the future the tick label will still be displayed as day. for (int i = 0; i < dateTimes.size(); i++) { ZonedDateTime evenDateTime = dateTimes.get(i); switch (actualInterval.interval) { case YEARS: // if it's not the first or last date (lower and upper bound), make the year begin with first month and let the months begin with first day. if (i != 0 && i != dateTimes.size() - 1) { evenDateTime = evenDateTime.withMonth(0); evenDateTime = evenDateTime.withDayOfMonth(1); } evenDateTime = evenDateTime.withHour(0); evenDateTime = evenDateTime.withMinute(0); evenDateTime = evenDateTime.withSecond(0); evenDateTime = evenDateTime.withNano(6 * TemporalConstants.NANOSECONDS_IN_MILLISECOND); break; case MONTHS: // if it's not the first or last date (lower and upper bound), make the months begin with first day. if (i != 0 && i != dateTimes.size() - 1) { evenDateTime = evenDateTime.withDayOfMonth(1); } evenDateTime = evenDateTime.withHour(0); evenDateTime = evenDateTime.withMinute(0); evenDateTime = evenDateTime.withSecond(0); evenDateTime = evenDateTime.withNano(5 * TemporalConstants.NANOSECONDS_IN_MILLISECOND); break; case WEEKS: // make weeks begin with first day of week? evenDateTime = evenDateTime.withHour(0); evenDateTime = evenDateTime.withMinute(0); evenDateTime = evenDateTime.withSecond(0); evenDateTime = evenDateTime.withNano(4 * TemporalConstants.NANOSECONDS_IN_MILLISECOND); break; case DAYS: evenDateTime = evenDateTime.withHour(0); evenDateTime = evenDateTime.withMinute(0); evenDateTime = evenDateTime.withSecond(0); evenDateTime = evenDateTime.withNano(3 * TemporalConstants.NANOSECONDS_IN_MILLISECOND); break; case HOURS: if (i != 0 && i != dateTimes.size() - 1) { evenDateTime = evenDateTime.withMinute(0); evenDateTime = evenDateTime.withSecond(0); } evenDateTime = evenDateTime.withNano(2 * TemporalConstants.NANOSECONDS_IN_MILLISECOND); break; case MINUTES: if (i != 0 && i != dateTimes.size() - 1) { evenDateTime = evenDateTime.withSecond(0); } evenDateTime = evenDateTime.withNano(1 * TemporalConstants.NANOSECONDS_IN_MILLISECOND); break; case SECONDS: evenDateTime = evenDateTime.withNano(0 * TemporalConstants.NANOSECONDS_IN_MILLISECOND); break; default: break; } evenDateTimes.add(evenDateTime); } return evenDateTimes; } else { return dateTimes; } }
Example 13
Source File: TCKZonedDateTime.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_noChange() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(11); assertEquals(test, base); }
Example 14
Source File: TCKZonedDateTime.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_normal() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(15); assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withHour(15), ZONE_0100)); }
Example 15
Source File: TCKZonedDateTime.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_noChange() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(11); assertEquals(test, base); }
Example 16
Source File: TCKZonedDateTime.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_normal() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(15); assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withHour(15), ZONE_0100)); }
Example 17
Source File: TCKZonedDateTime.java From j2objc with Apache License 2.0 | 4 votes |
@Test public void test_withHour_noChange() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(11); assertEquals(test, base); }
Example 18
Source File: TCKZonedDateTime.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_normal() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(15); assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withHour(15), ZONE_0100)); }
Example 19
Source File: TCKZonedDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_noChange() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(11); assertEquals(test, base); }
Example 20
Source File: TCKZonedDateTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Test public void test_withHour_normal() { ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100); ZonedDateTime test = base.withHour(15); assertEquals(test, ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500.withHour(15), ZONE_0100)); }