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())); } }
private ZoneId getZone(DeserializationContext context) { // Instants are always in UTC, so don't waste compute cycles return (_valueClass == Instant.class) ? null : context.getTimeZone().toZoneId(); }
@Nullable private OffsetDateTime convertToOffsetDateTime(Timestamp timestamp) { if (timestamp == null) { return null; } final Optional<ZoneId> zoneId = calendar.flatMap(c -> Optional.of(c.getTimeZone().toZoneId())); return OffsetDateTime.ofInstant( Instant.ofEpochSecond(timestamp.getTime() / 1000, timestamp.getNanos()), zoneId.orElse(ZoneId.systemDefault())); } }
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()); } }
/** * Set the zoneId from timestamp for datestamps in the log * * @param timezone to use * @return this builder * @deprecated use {@link #withZoneId(ZoneId)} */ @Deprecated public Builder withTimeZone( TimeZone timezone ) { return withZoneId( timezone.toZoneId() ); }
/** * Set the zoneId for datestamps in the log * * @return this builder * @param timezone to use * @deprecated use {@link #withZoneId(ZoneId)} */ @Deprecated public Builder withTimeZone( TimeZone timezone ) { return this.withZoneId( timezone.toZoneId() ); }
/** */ public String getFormattedStartTime() { return dateTimeFormatter.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(startTime), TimeZone.getDefault().toZoneId())); }
public static LocalDateTime fromCalendar(final Calendar calendar) { TimeZone tz = calendar.getTimeZone(); ZoneId zid = tz == null ? ZoneId.systemDefault() : tz.toZoneId(); return LocalDateTime.ofInstant(calendar.toInstant(), zid); }
/** * Start creating a {@link FormattedLog} with the specified zoneId from timezone for datestamps in the log * * @param timezone to use * @return a builder for a {@link FormattedLog} * @deprecated use {@link #withZoneId(ZoneId)} */ @Deprecated public static Builder withTimeZone( TimeZone timezone ) { return new Builder().withZoneId( timezone.toZoneId() ); }
/** * Start creating a {@link FormattedLogProvider} with the specified zoneId from timezone for datestamps in the log * * @param timeZone to use * @return a builder for a {@link FormattedLogProvider} * @deprecated use {@link #withZoneId(ZoneId)} */ @Deprecated public static Builder withTimeZone( TimeZone timeZone ) { return new Builder().withZoneId( timeZone.toZoneId() ); }
private static String dateTimeToDate(String timestamp, TimeZone timeZone) { Date date = parseDateTime(timestamp); return date.toInstant().atZone(timeZone.toZoneId()).toLocalDate().toString(); }
return (timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault());
protected TimestampFormatter createTimestampFormatter(TimeZone timeZone) { return new TimestampFormatter(getTimestampFormat(), timeZone.toZoneId()); } }
dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId());
@Test public void createDateTimeFormatterWithTimeZone() { factory.setPattern("yyyyMMddHHmmss Z"); factory.setTimeZone(TEST_TIMEZONE); ZoneId dateTimeZone = TEST_TIMEZONE.toZoneId(); ZonedDateTime dateTime = ZonedDateTime.of(2009, 10, 21, 12, 10, 00, 00, dateTimeZone); String offset = (TEST_TIMEZONE.equals(NEW_YORK) ? "-0400" : "+0200"); assertThat(factory.createDateTimeFormatter().format(dateTime), is("20091021121000 " + offset)); }
out.writeLong(dateTime.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli());
/** * Get the DateTimeFormatter with the this context's settings * applied to the base {@code formatter}. * @param formatter the base formatter that establishes default * formatting rules, generally context-independent * @return the contextual DateTimeFormatter */ public DateTimeFormatter getFormatter(DateTimeFormatter formatter) { if (this.chronology != null) { formatter = formatter.withChronology(this.chronology); } if (this.timeZone != null) { formatter = formatter.withZone(this.timeZone); } else { LocaleContext localeContext = LocaleContextHolder.getLocaleContext(); if (localeContext instanceof TimeZoneAwareLocaleContext) { TimeZone timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone(); if (timeZone != null) { formatter = formatter.withZone(timeZone.toZoneId()); } } } return formatter; }
LocaleContext localeContext = exchange.getLocaleContext(); TimeZone timeZone = getTimeZone(localeContext); return (timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault());
@Test public void zoneIdFromResolver() throws Exception { TimeZone timeZone = TimeZone.getTimeZone("America/New_York"); servletRequest.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(Locale.US, timeZone)); MethodParameter zoneIdParameter = new MethodParameter(method, 9); assertTrue("ZoneId not supported", resolver.supportsParameter(zoneIdParameter)); Object result = resolver.resolveArgument(zoneIdParameter, null, webRequest, null); assertEquals("Invalid result", timeZone.toZoneId(), result); }