java.util.TimeZone.toZoneId()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(175)

本文整理了Java中java.util.TimeZone.toZoneId()方法的一些代码示例,展示了TimeZone.toZoneId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimeZone.toZoneId()方法的具体详情如下:
包路径:java.util.TimeZone
类名称:TimeZone
方法名:toZoneId

TimeZone.toZoneId介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

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());
  }
}

代码示例来源:origin: dropwizard/dropwizard

@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()));
  }
}

代码示例来源:origin: prestodb/presto

private ZoneId getZone(DeserializationContext context)
{
  // Instants are always in UTC, so don't waste compute cycles
  return (_valueClass == Instant.class) ? null : context.getTimeZone().toZoneId();
}

代码示例来源:origin: dropwizard/dropwizard

@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()));
  }
}

代码示例来源:origin: org.springframework/spring-context

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());
  }
}

代码示例来源:origin: neo4j/neo4j

/**
 * 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() );
}

代码示例来源:origin: neo4j/neo4j

/**
 * 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() );
}

代码示例来源:origin: apache/ignite

/** */
public String getFormattedStartTime() {
  return dateTimeFormatter.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(startTime), TimeZone.getDefault().toZoneId()));
}

代码示例来源:origin: oblac/jodd

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);
}

代码示例来源:origin: neo4j/neo4j

/**
 * 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() );
}

代码示例来源:origin: neo4j/neo4j

/**
 * 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() );
}

代码示例来源:origin: SonarSource/sonarqube

private static String dateTimeToDate(String timestamp, TimeZone timeZone) {
 Date date = parseDateTime(timestamp);
 return date.toInstant().atZone(timeZone.toZoneId()).toLocalDate().toString();
}

代码示例来源:origin: spring-projects/spring-framework

return (timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault());

代码示例来源:origin: dropwizard/dropwizard

protected TimestampFormatter createTimestampFormatter(TimeZone timeZone) {
    return new TimestampFormatter(getTimestampFormat(), timeZone.toZoneId());
  }
}

代码示例来源:origin: spring-projects/spring-framework

dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId());

代码示例来源:origin: spring-projects/spring-framework

@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));
}

代码示例来源:origin: alibaba/fastjson

out.writeLong(dateTime.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli());

代码示例来源:origin: spring-projects/spring-framework

/**
 * 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;
}

代码示例来源:origin: spring-projects/spring-framework

LocaleContext localeContext = exchange.getLocaleContext();
TimeZone timeZone = getTimeZone(localeContext);
return (timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault());

代码示例来源:origin: spring-projects/spring-framework

@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);
}

相关文章