Refine search
protected ZonedDateTimeWithZoneIdSerializer() { super(ZonedDateTime.class, dt -> dt.toInstant().toEpochMilli(), ZonedDateTime::toEpochSecond, ZonedDateTime::getNano, // Serialize in a backwards compatible way: with zone id, using toString method null); }
public Date format(String date, String pattern) { DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern, Locale.US); LocalDateTime formatted = LocalDateTime.parse(date, fmt); Instant instant = formatted.atZone(ZoneId.systemDefault()).toInstant(); return Date.from(instant); }
/** * format string time to unix time * * @param time string date * @param pattern date format pattern * @return return unix time */ public static int toUnix(String time, String pattern) { LocalDateTime formatted = LocalDateTime.parse(time, DateTimeFormatter.ofPattern(pattern)); return (int) formatted.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond(); }
/** * Converts local date time to epoh milliseconds. */ public static long toMilliseconds(final LocalDateTime localDateTime) { return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); }
Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant(); return (X) java.sql.Timestamp.from( instant ); Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant(); return (X) java.sql.Date.from( instant ); Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant(); return (X) java.sql.Time.from( instant ); Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant(); return (X) java.util.Date.from( instant ); Instant instant = value.atZone( ZoneId.systemDefault() ).toInstant(); return (X) Long.valueOf( instant.toEpochMilli() );
@Override public void serialize(ZonedDateTime zonedDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { final Instant instant = zonedDateTime.withZoneSameInstant(ZoneOffset.UTC).toInstant(); final Date date = Date.from(instant); jsonGenerator.writeObject(date); } }
@Override @SuppressWarnings("unchecked") public <X> X unwrap(ZonedDateTime zonedDateTime, Class<X> type, WrapperOptions options) { if ( zonedDateTime == null ) { return null; } if ( ZonedDateTime.class.isAssignableFrom( type ) ) { return (X) zonedDateTime; } if ( Calendar.class.isAssignableFrom( type ) ) { return (X) GregorianCalendar.from( zonedDateTime ); } if ( Timestamp.class.isAssignableFrom( type ) ) { return (X) Timestamp.from( zonedDateTime.toInstant() ); } if ( java.sql.Date.class.isAssignableFrom( type ) ) { return (X) java.sql.Date.from( zonedDateTime.toInstant() ); } if ( java.sql.Time.class.isAssignableFrom( type ) ) { return (X) java.sql.Time.from( zonedDateTime.toInstant() ); } if ( Date.class.isAssignableFrom( type ) ) { return (X) Date.from( zonedDateTime.toInstant() ); } if ( Long.class.isAssignableFrom( type ) ) { return (X) Long.valueOf( zonedDateTime.toInstant().toEpochMilli() ); } throw unknownUnwrap( type ); }
/** * Converts local date to Date. */ public static Date toDate(final LocalDate localDate) { return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); } /**
public ZonedDateTimeSerializer(DateTimeFormatter formatter) { super(ZonedDateTime.class, dt -> dt.toInstant().toEpochMilli(), ZonedDateTime::toEpochSecond, ZonedDateTime::getNano, formatter); _writeZoneId = null; }
private Date acquireData() { return new Date(LocalDateTime.now().atZone(ZoneId.systemDefault()) .toInstant().toEpochMilli() - (hmilyConfig.getRecoverDelayTime() * 1000)); }
@Override @SuppressWarnings("unchecked") public <X> X unwrap(LocalDate value, Class<X> type, WrapperOptions options) { if ( value == null ) { return null; } if ( LocalDate.class.isAssignableFrom( type ) ) { return (X) value; } if ( java.sql.Date.class.isAssignableFrom( type ) ) { return (X) java.sql.Date.valueOf( value ); } final LocalDateTime localDateTime = value.atStartOfDay(); if ( Timestamp.class.isAssignableFrom( type ) ) { return (X) Timestamp.valueOf( localDateTime ); } final ZonedDateTime zonedDateTime = localDateTime.atZone( ZoneId.systemDefault() ); if ( Calendar.class.isAssignableFrom( type ) ) { return (X) GregorianCalendar.from( zonedDateTime ); } final Instant instant = zonedDateTime.toInstant(); if ( Date.class.equals( type ) ) { return (X) Date.from( instant ); } if ( Long.class.isAssignableFrom( type ) ) { return (X) Long.valueOf( instant.toEpochMilli() ); } throw unknownUnwrap( type ); }
public String getBearerToken(String subject) { checkState(jwtSigner.isPresent(), "not configured"); JwtBuilder jwt = Jwts.builder() .setSubject(subject) .setExpiration(Date.from(ZonedDateTime.now().plusMinutes(5).toInstant())); jwtSigner.get().accept(jwt); jwtKeyId.ifPresent(keyId -> jwt.setHeaderParam(KEY_ID, keyId)); jwtIssuer.ifPresent(jwt::setIssuer); jwtAudience.ifPresent(jwt::setAudience); return jwt.compact(); }
/** * format string time to unix time * * @param time string date * @param pattern date format pattern * @return return unix time */ public static int toUnix(String time, String pattern) { LocalDateTime formatted = LocalDateTime.parse(time, DateTimeFormatter.ofPattern(pattern)); return (int) formatted.atZone(ZoneId.systemDefault()).toInstant().getEpochSecond(); }
@Override @SuppressWarnings("unchecked") public <X> X unwrap(OffsetTime offsetTime, Class<X> type, WrapperOptions options) { if ( offsetTime == null ) { return null; } if ( OffsetTime.class.isAssignableFrom( type ) ) { return (X) offsetTime; } if ( java.sql.Time.class.isAssignableFrom( type ) ) { return (X) java.sql.Time.valueOf( offsetTime.toLocalTime() ); } final ZonedDateTime zonedDateTime = offsetTime.atDate( LocalDate.of( 1970, 1, 1 ) ).toZonedDateTime(); if ( Timestamp.class.isAssignableFrom( type ) ) { return (X) Timestamp.valueOf( zonedDateTime.toLocalDateTime() ); } if ( Calendar.class.isAssignableFrom( type ) ) { return (X) GregorianCalendar.from( zonedDateTime ); } final Instant instant = zonedDateTime.toInstant(); if ( Long.class.isAssignableFrom( type ) ) { return (X) Long.valueOf( instant.toEpochMilli() ); } if ( java.util.Date.class.isAssignableFrom( type ) ) { return (X) java.util.Date.from( instant ); } throw unknownUnwrap( type ); }
public Date format(String date, String pattern) { DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern, Locale.US); LocalDateTime formatted = LocalDateTime.parse(date, fmt); Instant instant = formatted.atZone(ZoneId.systemDefault()).toInstant(); return Date.from(instant); }
protected ZonedDateTimeWithZoneIdSerializer() { super(ZonedDateTime.class, dt -> dt.toInstant().toEpochMilli(), ZonedDateTime::toEpochSecond, ZonedDateTime::getNano, // Serialize in a backwards compatible way: with zone id, using toString method null); }
private Date acquireData() { return new Date(LocalDateTime.now() .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() - (txConfig.getRecoverDelayTime() * 1000)); }
final ZonedDateTime zonedDateTime = value.atDate( LocalDate.of( 1970, 1, 1 ) ).atZone( ZoneId.systemDefault() ); final Instant instant = zonedDateTime.toInstant(); return (X) Date.from( instant ); return (X) Long.valueOf( instant.toEpochMilli() );
@CheckForNull private static Instant parseDate(String propertyValue) { try { LocalDate localDate = LocalDate.parse(propertyValue); return localDate.atStartOfDay(ZoneId.systemDefault()).toInstant(); } catch (DateTimeParseException e) { boolean invalidDate = e.getCause() == null || e.getCause() == e || !e.getCause().getMessage().contains("Invalid date"); checkPeriodProperty(invalidDate, propertyValue, "Invalid date"); return null; } }