static String formatDate(long date) { Instant instant = Instant.ofEpochMilli(date); ZonedDateTime time = ZonedDateTime.ofInstant(instant, GMT); return DATE_FORMATTERS[0].format(time); }
/** * Set the given date under the given header name after formatting it as a string * using the RFC-1123 date-time formatter. The equivalent of * {@link #set(String, String)} but for date headers. * @since 5.1.4 */ public void setInstant(String headerName, Instant date) { setZonedDateTime(headerName, ZonedDateTime.ofInstant(date, GMT)); }
static String formatDate(long date) { Instant instant = Instant.ofEpochMilli(date); ZonedDateTime time = ZonedDateTime.ofInstant(instant, GMT); return DATE_FORMATTERS[0].format(time); }
@JsonCreator public AtopSplit( @JsonProperty("table") AtopTable table, @JsonProperty("host") HostAddress host, @JsonProperty("epochSeconds") long epochSeconds, @JsonProperty("timeZone") ZoneId timeZone) { this.table = requireNonNull(table, "table name is null"); this.host = requireNonNull(host, "host is null"); requireNonNull(timeZone, "timeZone is null"); this.date = ZonedDateTime.ofInstant(ofEpochSecond(epochSeconds), timeZone); }
@Override public String objectToSQLString(Instant value, Dialect dialect) throws Exception { return "{ts '" + FORMATTER.format( ZonedDateTime.ofInstant( value, ZoneId.of( "UTC" ) ) ) + "'}"; }
private static ZonedDateTime calendarToZonedDateTime(Calendar source) { if (source instanceof GregorianCalendar) { return ((GregorianCalendar) source).toZonedDateTime(); } else { return ZonedDateTime.ofInstant(Instant.ofEpochMilli(source.getTimeInMillis()), source.getTimeZone().toZoneId()); } }
@Nullable private ZonedDateTime convertToZonedDateTime(Timestamp timestamp) { if (timestamp == null) { return null; } final Optional<ZoneId> zoneId = calendar.flatMap(c -> Optional.of(c.getTimeZone().toZoneId())); return ZonedDateTime.ofInstant( Instant.ofEpochSecond(timestamp.getTime() / 1000, timestamp.getNanos()), zoneId.orElse(ZoneId.systemDefault())); } }
public static ZonedDateTime datetimeRaw( long epochSecondUTC, long nano, ZoneId zone ) { return assertValidArgument( () -> ofInstant( ofEpochSecond( epochSecondUTC, nano ), zone ) ); }
private ZonedDateTime nextZonedDateTimeRaw( ZoneId utc ) { return ZonedDateTime.ofInstant( nextInstantRaw(), utc ); }
/** * Set the given date under the given header name after formatting it as a string * using the RFC-1123 date-time formatter. The equivalent of * {@link #set(String, String)} but for date headers. * @since 5.1.4 */ public void setInstant(String headerName, Instant date) { setZonedDateTime(headerName, ZonedDateTime.ofInstant(date, GMT)); }
/** * Obtains an instance of Instant using seconds from the epoch of 1970-01-01T00:00:00Z and * nanosecond fraction of second. Then, it creates a zoned date-time with the same instant * as that specified but in the given time-zone. */ public void set(long seconds, int nanos, ZoneId timeZone) { Instant instant = Instant.ofEpochSecond(seconds, nanos); setZonedDateTime(ZonedDateTime.ofInstant(instant, timeZone)); }
private static ZonedDateTime calendarToZonedDateTime(Calendar source) { if (source instanceof GregorianCalendar) { return ((GregorianCalendar) source).toZonedDateTime(); } else { return ZonedDateTime.ofInstant(Instant.ofEpochMilli(source.getTimeInMillis()), source.getTimeZone().toZoneId()); } }
/** * Adds the LAST_MODIFIED header for the given {@link ZonedDateTime}. * * @param timeInMillis The current time in milli seconds * @return The {@link MutableHttpHeaders} */ default MutableHttpHeaders lastModified(long timeInMillis) { ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timeInMillis), ZoneId.of("GMT")); add(LAST_MODIFIED, date.format(DateTimeFormatter.RFC_1123_DATE_TIME)); return this; }
/** * Adds the DATE header for the given {@link ZonedDateTime}. * * @param timeInMillis The current time in milli seconds * @return The {@link MutableHttpHeaders} */ default MutableHttpHeaders date(long timeInMillis) { ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timeInMillis), ZoneId.of("GMT")); add(DATE, date.format(DateTimeFormatter.RFC_1123_DATE_TIME)); return this; }
private static ArrayValue readDateTimeArray( ByteBuffer bb, int offset ) { final int len = bb.getInt( offset ); offset += Integer.BYTES; final ZonedDateTime[] array = new ZonedDateTime[len]; for ( int i = 0; i < len; i++ ) { final long epocSeconds = bb.getLong( offset ); offset += Long.BYTES; final int nanos = bb.getInt( offset ); offset += Integer.BYTES; final int z = bb.getInt( offset ); offset += Integer.BYTES; array[i] = ZonedDateTime.ofInstant( Instant.ofEpochSecond( epocSeconds, nanos ), toZoneId( z ) ); } return dateTimeArray( array ); }
@Override OffsetTime getTimePart( Supplier<ZoneId> defaultZone ) { ZoneOffset currentOffset = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), defaultZone.get() ) ).getOffset(); return OffsetTime.of( value, currentOffset ); }
public static DateTimeValue ofEpochMillis( IntegralValue millisUTC ) { return new DateTimeValue( assertValidArgument( () -> ofInstant( ofEpochMilli( millisUTC.longValue() ), UTC ) ) ); }
@Override public ZonedDateTime convertToMapped(Class<? extends ZonedDateTime> type, Timestamp value) { if (value == null) { return null; } Instant instant = value.toInstant(); return ZonedDateTime.ofInstant(instant, ZoneOffset.systemDefault()); } }
@Override OffsetTime getTimePart( Supplier<ZoneId> defaultZone ) { ZoneOffset currentOffset = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), defaultZone.get() ) ).getOffset(); return OffsetTime.of(value.toLocalTime(), currentOffset); }
@Override public Object read( ReadableClosableChannel from ) throws IOException { if ( from.get() == (byte) 0 ) { long epochSecondsUTC = from.getLong(); int nanos = from.getInt(); int offsetSeconds = from.getInt(); return ZonedDateTime.ofInstant( Instant.ofEpochSecond( epochSecondsUTC, nanos ), ZoneOffset.ofTotalSeconds( offsetSeconds ) ); } else { long epochSecondsUTC = from.getLong(); int nanos = from.getInt(); int zoneID = from.getInt(); String zone = TimeZones.map( (short) zoneID ); return ZonedDateTime.ofInstant( Instant.ofEpochSecond( epochSecondsUTC, nanos ), ZoneId.of( zone ) ); } }