@Override public long applyAsLong(ZonedDateTime dt) { return dt.toInstant().toEpochMilli(); } },
private String convertDateToSlackTimestamp(ZonedDateTime date) { return (date.toInstant().toEpochMilli() / 1000) + ".123456"; }
@Nullable public static Long localDateTimeToLong(@Nullable LocalDateTime d) { if (d == null) { return null; } return d.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); }
@Nonnull @Override public java.time.Instant convert(LocalDateTime source) { return java.time.Instant.ofEpochMilli(source.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli()); } }
@Nonnull @Override public Date convert(LocalDateTime source) { return toDate(source.atZone(systemDefault()).toInstant()); } }
@Nonnull @Override public Date convert(LocalDate source) { return toDate(source.atStartOfDay(systemDefault()).toInstant()); } }
@Nonnull @Override public Date convert(Instant source) { return toDate(source.atZone(systemDefault()).toInstant()); } }
@Nonnull @Override public java.time.LocalDateTime convert(LocalDateTime source) { Date date = toDate(source.atZone(ZoneId.systemDefault()).toInstant()); return Jsr310Converters.DateToLocalDateTimeConverter.INSTANCE.convert(date); } }
default java.util.Date map(org.threeten.bp.LocalDate value) { return value != null ? DateTimeUtils.toDate(value.atStartOfDay(ZoneId.systemDefault()).toInstant()) : null; } }
@Nonnull @Override public Date convert(LocalTime source) { return toDate(source.atDate(LocalDate.now()).atZone(systemDefault()).toInstant()); } }
/** * Converts a {@code ZonedDateTime} to a {@code Calendar}. * <p> * The resulting {@code GregorianCalendar} is pure Gregorian and uses * ISO week definitions, starting on Monday and with 4 days in a minimal week. * <p> * Fractions of the instant smaller than milliseconds will be dropped. * * @param zdt the zoned date-time, not null * @return the calendar, not null * @throws IllegalArgumentException if the conversion fails */ public static GregorianCalendar toGregorianCalendar(ZonedDateTime zdt) { TimeZone zone = toTimeZone(zdt.getZone()); GregorianCalendar cal = new GregorianCalendar(zone); cal.setGregorianChange(new Date(Long.MIN_VALUE)); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.setMinimalDaysInFirstWeek(4); try { cal.setTimeInMillis(zdt.toInstant().toEpochMilli()); } catch (ArithmeticException ex) { throw new IllegalArgumentException(ex); } return cal; }
/** * Converts a {@code ZonedDateTime} to a {@code Calendar}. * <p> * The resulting {@code GregorianCalendar} is pure Gregorian and uses * ISO week definitions, starting on Monday and with 4 days in a minimal week. * <p> * Fractions of the instant smaller than milliseconds will be dropped. * * @param zdt the zoned date-time, not null * @return the calendar, not null * @throws IllegalArgumentException if the conversion fails */ public static GregorianCalendar toGregorianCalendar(ZonedDateTime zdt) { TimeZone zone = toTimeZone(zdt.getZone()); GregorianCalendar cal = new GregorianCalendar(zone); cal.setGregorianChange(new Date(Long.MIN_VALUE)); cal.setFirstDayOfWeek(Calendar.MONDAY); cal.setMinimalDaysInFirstWeek(4); try { cal.setTimeInMillis(zdt.toInstant().toEpochMilli()); } catch (ArithmeticException ex) { throw new IllegalArgumentException(ex); } return cal; }