public String timestamp() { if (timestamp == 0) { return "n/a"; } return Instant.ofEpochMilli(timestamp) .atOffset(ZoneOffset.UTC) .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); }
@Override public ZonedDateTime convert(String source) { ZonedDateTime dateTime; try { long epoch = Long.parseLong(source); dateTime = Instant.ofEpochMilli(epoch).atOffset(ZoneOffset.ofTotalSeconds(0)) .toZonedDateTime(); } catch (NumberFormatException e) { // try ZonedDateTime instead dateTime = ZonedDateTime.parse(source); } return dateTime; } }
@Override public LocalTime decode(final BsonReader reader, final DecoderContext decoderContext) { return Instant.ofEpochMilli(validateAndReadDateTime(reader)).atOffset(ZoneOffset.UTC).toLocalTime(); }
value = clock.instant().atOffset(ZoneOffset.UTC).get(ChronoField.YEAR) + value;
/** * Applies local time zone offset to timestamp value read using specified {@code reader}. * * @param writer writer to store string representation of timestamp value * @param fieldName name of the field * @param reader document reader */ @Override protected void writeTimeStamp(MapOrListWriterImpl writer, String fieldName, DocumentReader reader) { String formattedTimestamp = Instant.ofEpochMilli(reader.getTimestampLong()) .atOffset(OffsetDateTime.now().getOffset()).format(DateUtility.UTC_FORMATTER); writeString(writer, fieldName, formattedTimestamp); } };
OffsetDateTime expires = (maxAge != 0) ? OffsetDateTime.now().plusSeconds(maxAge) : Instant.EPOCH.atOffset(ZoneOffset.UTC); sb.append("; Expires=") .append(expires.format(DateTimeFormatter.RFC_1123_DATE_TIME));
@Override public IdCreateTime map(ResultSet rs, StatementContext ctx) throws SQLException { return new IdCreateTime( rs.getLong("id"), rs.getTimestamp("created_on").toInstant().atOffset(ZoneOffset.UTC)); } }
Instant notAfter = notBefore.atOffset(ZoneOffset.UTC).plusYears(30).toInstant();
public static String formatHttpDate(Instant instant){ // TODO java 7 incompatible return DateTimeFormatter.RFC_1123_DATE_TIME.format(instant.atOffset(ZoneOffset.UTC)); } public static void writeDOM(Node node, OutputStream out, String encoding) throws TransformerException, UnsupportedEncodingException{
OffsetDateTime timestamp = Instant.ofEpochSecond(content.getInt("timestamp")).atOffset(ZoneOffset.UTC); getJDA().getEventManager().handle( new UserTypingEvent(
@Nonnull @CheckReturnValue public static OffsetDateTime creationTimeOf(final long id) { final long discordTimestamp = id >> 22; final Instant instant = Instant.ofEpochMilli(discordTimestamp + DISCORD_EPOCH); return instant.atOffset(ZoneOffset.UTC); }
private String makeSnapshotReleaseString () { if ( this.snapshotBuildId == null || this.snapshotBuildId.isEmpty () ) { final DateTimeFormatter formatter = DateTimeFormatter.ofPattern ( "yyyyMMddHHmm", Locale.ROOT ); return this.snapshotReleasePrefix + formatter.format ( Instant.now ().atOffset ( ZoneOffset.UTC ) ); } else { return this.snapshotReleasePrefix + this.snapshotBuildId; } }
/** * Returns a {@link LocalDateTime} instance representing the given {@link Date} according to UTC. * * @return a date time in UTC */ public static LocalDateTime toLocalDateTime(Date date) { return Optional.ofNullable(date) .map(Date::toInstant) .map(i -> i.atOffset(UTC)) .map(OffsetDateTime::toLocalDateTime) .orElse(null); }
private static String formatMonth(Instant instant) { return ISO_LOCAL_MONTH.format( instant.truncatedTo(ChronoUnit.DAYS) .atOffset(UTC)); }
@Override public OffsetTime fromNonNullValue(Time value) { return Instant.ofEpochMilli(value.getTime()).atOffset(javaZone).toOffsetTime(); }
/** * Create new header, with instant */ public static Header ofDate(String name, Instant instant) { requireNonNull(name); requireNonNull(instant); return new Header(name, RFC_1123_DATE_TIME.format(instant.atOffset(UTC))); }
private static String formatDateTime(Instant instant) { return ISO_OFFSET_DATE_TIME.format( instant.truncatedTo(ChronoUnit.MINUTES) .atOffset(UTC)); }
@Override public OffsetDateTime toRawValue(Date flatValue) { return flatValue.toInstant().atOffset(OffsetDateTime.now().getOffset()); } }
/** * Calculates the amount of time in {@code unit}. * <p> * The start point of time is taken to be {@link Instant#EPOCH}, and the time zone is {@link ZoneOffset#UTC}. * @param unit the unit * @return the amount of time specified by this instance */ public long getAmountOf(final ChronoUnit unit) { final OffsetDateTime epoch = Instant.EPOCH.atOffset(ZoneOffset.UTC); return unit.between(epoch, epoch.plus(this)); } }
private static String toYahooQueryDate(Instant instant, String names) { OffsetDateTime time = instant.atOffset(ZoneOffset.UTC); String[] strings = names.split(""); return format("%s=%d&%s=%d&%s=%d", strings[0], time.getMonthValue() - 1, strings[1], time.getDayOfMonth(), strings[2], time.getYear()); } }