Java Code Examples for java.time.LocalDateTime#toLocalDate()
The following examples show how to use
java.time.LocalDateTime#toLocalDate() .
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-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public void test_plusHours_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.plusHours(1); if ((i + 1) % 24 == 0) { d = d.plusDays(1); } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (i + 1) % 24); } }
Example 2
Source File: TCKLocalDateTime.java From hottub 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 j2objc with Apache License 2.0 | 6 votes |
@Test public void test_plusHours_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.plusHours(1); if ((i + 1) % 24 == 0) { d = d.plusDays(1); } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (i + 1) % 24); } }
Example 4
Source File: TCKLocalDateTime.java From openjdk-jdk8u 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 5
Source File: TCKLocalDateTime.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_plusMinutes_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0; int min = 0; for (int i = 0; i < 70; i++) { t = t.plusMinutes(1); min++; if (min == 60) { hour++; min = 0; } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); } }
Example 6
Source File: TCKLocalDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Test public void test_plusHours_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.plusHours(1); if ((i + 1) % 24 == 0) { d = d.plusDays(1); } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (i + 1) % 24); } }
Example 7
Source File: DateTest.java From java-master with Apache License 2.0 | 6 votes |
@Test public void test() { LocalDate date = LocalDate.of(2014, 3, 18); LocalTime time = LocalTime.of(10, 3, 18); int year = date.getYear(); Month month = date.getMonth(); int day = date.getDayOfMonth(); DayOfWeek dow = date.getDayOfWeek(); int len = date.lengthOfMonth(); boolean leap = date.isLeapYear(); // 还可以使用工厂方法从系统时钟中获取当前的日期: LocalDate today = LocalDate.now(); // LocalDateTime,是LocalDate和LocalTime的合体。它同时表示了日期和时间,但不带有时区信息 LocalDateTime dt1 = LocalDateTime.of(2014, Month.MARCH, 18, 13, 45, 20); LocalDateTime dt2 = LocalDateTime.of(date, time); // 也可以使用toLocalDate或者toLocalTime方法,从LocalDateTime中提取LocalDate或者LocalTime组件: LocalDate date1 = dt1.toLocalDate(); LocalTime time1 = dt1.toLocalTime(); }
Example 8
Source File: TCKLocalDateTime.java From hottub with GNU General Public License v2.0 | 6 votes |
@Test public void test_plusHours_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.plusHours(1); if ((i + 1) % 24 == 0) { d = d.plusDays(1); } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), (i + 1) % 24); } }
Example 9
Source File: TCKLocalDateTime.java From j2objc with Apache License 2.0 | 6 votes |
@Test public void test_plusMinutes_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0; int min = 0; for (int i = 0; i < 70; i++) { t = t.plusMinutes(1); min++; if (min == 60) { hour++; min = 0; } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); } }
Example 10
Source File: TCKLocalDateTime.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void test_plusNanos_halfABillion() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0; int min = 0; int sec = 0; int nanos = 0; for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) { t = t.plusNanos(500000000); nanos += 500000000; if (nanos == 1000000000) { sec++; nanos = 0; } if (sec == 60) { min++; sec = 0; } if (min == 60) { hour++; min = 0; } assertEquals(String.valueOf(i), t.toLocalDate(), d); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); assertEquals(t.getNano(), nanos); } }
Example 11
Source File: TCKLocalDateTime.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test public void test_plusSeconds_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0; int min = 0; int sec = 0; for (int i = 0; i < 3700; i++) { t = t.plusSeconds(1); sec++; if (sec == 60) { min++; sec = 0; } if (min == 60) { hour++; min = 0; } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); } }
Example 12
Source File: TCKLocalDateTime.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test public void test_plusSeconds_one() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0; int min = 0; int sec = 0; for (int i = 0; i < 3700; i++) { t = t.plusSeconds(1); sec++; if (sec == 60) { min++; sec = 0; } if (min == 60) { hour++; min = 0; } assertEquals(t.toLocalDate(), d); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); } }
Example 13
Source File: TCKLocalDateTime.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test public void test_plusNanos_halfABillion() { LocalDateTime t = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT); LocalDate d = t.toLocalDate(); int hour = 0; int min = 0; int sec = 0; int nanos = 0; for (long i = 0; i < 3700 * 1000000000L; i+= 500000000) { t = t.plusNanos(500000000); nanos += 500000000; if (nanos == 1000000000) { sec++; nanos = 0; } if (sec == 60) { min++; sec = 0; } if (min == 60) { hour++; min = 0; } assertEquals(t.toLocalDate(), d, String.valueOf(i)); assertEquals(t.getHour(), hour); assertEquals(t.getMinute(), min); assertEquals(t.getSecond(), sec); assertEquals(t.getNano(), nanos); } }
Example 14
Source File: TimeUtil.java From sumk with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static <T> T toType(LocalDateTime v, Class<?> type, boolean failIfNotSupport) { if (Date.class == type) { return (T) Date.from(v.atZone(ZoneId.systemDefault()).toInstant()); } if (java.sql.Date.class == type) { return (T) java.sql.Date.valueOf(v.toLocalDate()); } if (Timestamp.class == type) { return (T) Timestamp.valueOf(v); } if (Time.class == type) { return (T) Time.valueOf(v.toLocalTime()); } if (LocalDate.class == type) { return (T) v.toLocalDate(); } if (LocalTime.class == type) { return (T) v.toLocalTime(); } if (failIfNotSupport || !isGenericDate(type)) { throw new SumkException(868927175, type.getClass().getName() + "is not a supported Date type"); } return (T) v; }
Example 15
Source File: ServerStatusInfo.java From ClusterDeviceControlPlatform with MIT License | 5 votes |
public ServerStatusInfo(ServerCenterProcessor serverProcessor) { LocalDateTime start = ServerSetting.SYSTEM_START_DATE_TIME; StartTime = start.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME).replace('T', ' ').split("\\.")[0]; LocalDateTime now = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); LocalDate nowDate = now.toLocalDate(); LocalTime nowTime = now.toLocalTime(); currentDate = nowDate.format(DateTimeFormatter.ISO_DATE); currentTime = nowTime.format(DateTimeFormatter.ISO_TIME).split("\\.")[0]; Duration duration = Duration.between(start, now); long temp = duration.getSeconds(); long second = temp % 60; temp = temp / 60; long minutes = temp % 60; temp = temp / 60; long hour = temp % 24; long day = temp / 24; StringBuilder builder = new StringBuilder(); if (day != 0) { builder.append(day).append("日"); } builder.append(hour).append("时"); builder.append(minutes).append("分"); builder.append(second).append("秒"); runningTime = builder.toString(); exceptionMsgCount = serverProcessor.getTcpFeedBackItemsCount(TcpFeedBackRepository.ItemType.EXCEPTION); timeoutMsgCount = serverProcessor.getTcpFeedBackItemsCount(TcpFeedBackRepository.ItemType.TIMEOUT); }
Example 16
Source File: DateTimeConverters.java From spring-analysis-note with MIT License | 4 votes |
@Override public LocalDate convert(LocalDateTime source) { return source.toLocalDate(); }
Example 17
Source File: JavatimeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { int N = 10000; long t1970 = new java.util.Date(70, 0, 01).getTime(); Random r = new Random(); for (int i = 0; i < N; i++) { int days = r.nextInt(50) * 365 + r.nextInt(365); long secs = t1970 + days * 86400 + r.nextInt(86400); int nanos = r.nextInt(NANOS_PER_SECOND); int nanos_ms = nanos / 1000000 * 1000000; // millis precision long millis = secs * 1000 + r.nextInt(1000); LocalDateTime ldt = LocalDateTime.ofEpochSecond(secs, nanos, ZoneOffset.UTC); LocalDateTime ldt_ms = LocalDateTime.ofEpochSecond(secs, nanos_ms, ZoneOffset.UTC); Instant inst = Instant.ofEpochSecond(secs, nanos); Instant inst_ms = Instant.ofEpochSecond(secs, nanos_ms); //System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); /////////// Timestamp //////////////////////////////// Timestamp ta = new Timestamp(millis); ta.setNanos(nanos); if (!isEqual(ta.toLocalDateTime(), ta)) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(ta.toLocalDateTime(), ta); throw new RuntimeException("FAILED: j.s.ts -> ldt"); } if (!isEqual(ldt, Timestamp.valueOf(ldt))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(ldt, Timestamp.valueOf(ldt)); throw new RuntimeException("FAILED: ldt -> j.s.ts"); } Instant inst0 = ta.toInstant(); if (ta.getTime() != inst0.toEpochMilli() || ta.getNanos() != inst0.getNano() || !ta.equals(Timestamp.from(inst0))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); throw new RuntimeException("FAILED: j.s.ts -> instant -> j.s.ts"); } inst = Instant.ofEpochSecond(secs, nanos); Timestamp ta0 = Timestamp.from(inst); if (ta0.getTime() != inst.toEpochMilli() || ta0.getNanos() != inst.getNano() || !inst.equals(ta0.toInstant())) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); throw new RuntimeException("FAILED: instant -> timestamp -> instant"); } ////////// java.sql.Date ///////////////////////////// // j.s.d/t uses j.u.d.equals() !!!!!!!! java.sql.Date jsd = new java.sql.Date(millis); if (!isEqual(jsd.toLocalDate(), jsd)) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(jsd.toLocalDate(), jsd); throw new RuntimeException("FAILED: j.s.d -> ld"); } LocalDate ld = ldt.toLocalDate(); if (!isEqual(ld, java.sql.Date.valueOf(ld))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(ld, java.sql.Date.valueOf(ld)); throw new RuntimeException("FAILED: ld -> j.s.d"); } ////////// java.sql.Time ///////////////////////////// java.sql.Time jst = new java.sql.Time(millis); if (!isEqual(jst.toLocalTime(), jst)) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(jst.toLocalTime(), jst); throw new RuntimeException("FAILED: j.s.t -> lt"); } // millis precision LocalTime lt = ldt_ms.toLocalTime(); if (!isEqual(lt, java.sql.Time.valueOf(lt))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(lt, java.sql.Time.valueOf(lt)); throw new RuntimeException("FAILED: lt -> j.s.t"); } } System.out.println("Passed!"); }
Example 18
Source File: LeaveServiceImpl.java From axelor-open-suite with GNU Affero General Public License v3.0 | 4 votes |
/** * Computes the duration in hours of a leave, according to the weekly and the holiday plannings. * * @param weeklyPlanning * @param holidayPlanning * @param fromDateT * @param toDateT * @return * @throws AxelorException */ protected BigDecimal computeDurationInHours( LeaveRequest leave, Employee employee, LocalDateTime fromDateT, LocalDateTime toDateT) throws AxelorException { BigDecimal duration = BigDecimal.ZERO; WeeklyPlanning weeklyPlanning = getWeeklyPlanning(leave, employee); EventsPlanning holidayPlanning = getPublicHolidayEventsPlanning(leave, employee); LocalDate fromDate = fromDateT.toLocalDate(); LocalDate toDate = toDateT.toLocalDate(); if (toDate.equals(fromDate) && !publicHolidayHrService.checkPublicHolidayDay(fromDate, holidayPlanning)) { duration = duration.add( weeklyPlanningService.getWorkingDayValueInHours( weeklyPlanning, fromDate, fromDateT.toLocalTime(), toDateT.toLocalTime())); } else { // First day of leave if (!publicHolidayHrService.checkPublicHolidayDay(fromDate, holidayPlanning)) { duration = duration.add( weeklyPlanningService.getWorkingDayValueInHours( weeklyPlanning, fromDate, fromDateT.toLocalTime(), null)); } fromDate = fromDate.plusDays(1); // Last day of leave if (!publicHolidayHrService.checkPublicHolidayDay(toDate, holidayPlanning)) { duration = duration.add( weeklyPlanningService.getWorkingDayValueInHours( weeklyPlanning, toDate, null, toDateT.toLocalTime())); } // Daily leave duration of the other days between from and to date for (LocalDate date = fromDate; date.isBefore(toDate); date = date.plusDays(1)) { if (!publicHolidayHrService.checkPublicHolidayDay(date, holidayPlanning)) { duration = duration.add( weeklyPlanningService.getWorkingDayValueInHours( weeklyPlanning, date, null, null)); } } } return duration; }
Example 19
Source File: JavatimeTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { int N = 10000; long t1970 = new java.util.Date(70, 0, 01).getTime(); Random r = new Random(); for (int i = 0; i < N; i++) { int days = r.nextInt(50) * 365 + r.nextInt(365); long secs = t1970 + days * 86400 + r.nextInt(86400); int nanos = r.nextInt(NANOS_PER_SECOND); int nanos_ms = nanos / 1000000 * 1000000; // millis precision long millis = secs * 1000 + r.nextInt(1000); LocalDateTime ldt = LocalDateTime.ofEpochSecond(secs, nanos, ZoneOffset.UTC); LocalDateTime ldt_ms = LocalDateTime.ofEpochSecond(secs, nanos_ms, ZoneOffset.UTC); Instant inst = Instant.ofEpochSecond(secs, nanos); Instant inst_ms = Instant.ofEpochSecond(secs, nanos_ms); //System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); /////////// Timestamp //////////////////////////////// Timestamp ta = new Timestamp(millis); ta.setNanos(nanos); if (!isEqual(ta.toLocalDateTime(), ta)) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(ta.toLocalDateTime(), ta); throw new RuntimeException("FAILED: j.s.ts -> ldt"); } if (!isEqual(ldt, Timestamp.valueOf(ldt))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(ldt, Timestamp.valueOf(ldt)); throw new RuntimeException("FAILED: ldt -> j.s.ts"); } Instant inst0 = ta.toInstant(); if (ta.getTime() != inst0.toEpochMilli() || ta.getNanos() != inst0.getNano() || !ta.equals(Timestamp.from(inst0))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); throw new RuntimeException("FAILED: j.s.ts -> instant -> j.s.ts"); } inst = Instant.ofEpochSecond(secs, nanos); Timestamp ta0 = Timestamp.from(inst); if (ta0.getTime() != inst.toEpochMilli() || ta0.getNanos() != inst.getNano() || !inst.equals(ta0.toInstant())) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); throw new RuntimeException("FAILED: instant -> timestamp -> instant"); } ////////// java.sql.Date ///////////////////////////// // j.s.d/t uses j.u.d.equals() !!!!!!!! java.sql.Date jsd = new java.sql.Date(millis); if (!isEqual(jsd.toLocalDate(), jsd)) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(jsd.toLocalDate(), jsd); throw new RuntimeException("FAILED: j.s.d -> ld"); } LocalDate ld = ldt.toLocalDate(); if (!isEqual(ld, java.sql.Date.valueOf(ld))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(ld, java.sql.Date.valueOf(ld)); throw new RuntimeException("FAILED: ld -> j.s.d"); } ////////// java.sql.Time ///////////////////////////// java.sql.Time jst = new java.sql.Time(millis); if (!isEqual(jst.toLocalTime(), jst)) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(jst.toLocalTime(), jst); throw new RuntimeException("FAILED: j.s.t -> lt"); } // millis precision LocalTime lt = ldt_ms.toLocalTime(); if (!isEqual(lt, java.sql.Time.valueOf(lt))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(lt, java.sql.Time.valueOf(lt)); throw new RuntimeException("FAILED: lt -> j.s.t"); } } System.out.println("Passed!"); }
Example 20
Source File: JavatimeTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { int N = 10000; long t1970 = new java.util.Date(70, 0, 01).getTime(); Random r = new Random(); for (int i = 0; i < N; i++) { int days = r.nextInt(50) * 365 + r.nextInt(365); long secs = t1970 + days * 86400 + r.nextInt(86400); int nanos = r.nextInt(NANOS_PER_SECOND); int nanos_ms = nanos / 1000000 * 1000000; // millis precision long millis = secs * 1000 + r.nextInt(1000); LocalDateTime ldt = LocalDateTime.ofEpochSecond(secs, nanos, ZoneOffset.UTC); LocalDateTime ldt_ms = LocalDateTime.ofEpochSecond(secs, nanos_ms, ZoneOffset.UTC); Instant inst = Instant.ofEpochSecond(secs, nanos); Instant inst_ms = Instant.ofEpochSecond(secs, nanos_ms); //System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); /////////// Timestamp //////////////////////////////// Timestamp ta = new Timestamp(millis); ta.setNanos(nanos); if (!isEqual(ta.toLocalDateTime(), ta)) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(ta.toLocalDateTime(), ta); throw new RuntimeException("FAILED: j.s.ts -> ldt"); } if (!isEqual(ldt, Timestamp.valueOf(ldt))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(ldt, Timestamp.valueOf(ldt)); throw new RuntimeException("FAILED: ldt -> j.s.ts"); } Instant inst0 = ta.toInstant(); if (ta.getTime() != inst0.toEpochMilli() || ta.getNanos() != inst0.getNano() || !ta.equals(Timestamp.from(inst0))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); throw new RuntimeException("FAILED: j.s.ts -> instant -> j.s.ts"); } inst = Instant.ofEpochSecond(secs, nanos); Timestamp ta0 = Timestamp.from(inst); if (ta0.getTime() != inst.toEpochMilli() || ta0.getNanos() != inst.getNano() || !inst.equals(ta0.toInstant())) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); throw new RuntimeException("FAILED: instant -> timestamp -> instant"); } ////////// java.sql.Date ///////////////////////////// // j.s.d/t uses j.u.d.equals() !!!!!!!! java.sql.Date jsd = new java.sql.Date(millis); if (!isEqual(jsd.toLocalDate(), jsd)) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(jsd.toLocalDate(), jsd); throw new RuntimeException("FAILED: j.s.d -> ld"); } LocalDate ld = ldt.toLocalDate(); if (!isEqual(ld, java.sql.Date.valueOf(ld))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(ld, java.sql.Date.valueOf(ld)); throw new RuntimeException("FAILED: ld -> j.s.d"); } ////////// java.sql.Time ///////////////////////////// java.sql.Time jst = new java.sql.Time(millis); if (!isEqual(jst.toLocalTime(), jst)) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(jst.toLocalTime(), jst); throw new RuntimeException("FAILED: j.s.t -> lt"); } // millis precision LocalTime lt = ldt_ms.toLocalTime(); if (!isEqual(lt, java.sql.Time.valueOf(lt))) { System.out.printf("ms: %16d ns: %10d ldt:[%s]%n", millis, nanos, ldt); print(lt, java.sql.Time.valueOf(lt)); throw new RuntimeException("FAILED: lt -> j.s.t"); } } System.out.println("Passed!"); }