java.time.ZonedDateTime.withZoneSameInstant()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(208)

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

ZonedDateTime.withZoneSameInstant介绍

[英]Returns a copy of this date-time with a different time-zone, retaining the instant.

This method changes the time-zone and retains the instant. This normally results in a change to the local date-time.

This method is based on retaining the same instant, thus gaps and overlaps in the local time-line have no effect on the result.

To change the offset while keeping the local time, use #withZoneSameLocal(ZoneId).
[中]返回一个不同时区的日期时间副本,保留该时间。
此方法更改时区并保留瞬间。这通常会导致更改本地日期和时间。
该方法基于保留相同的瞬间,因此本地时间线中的间隔和重叠对结果没有影响。
要在保持本地时间的同时更改偏移量,请使用#withZoneSameLocal(ZoneId)。

代码示例

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

/**
 * Set the time the resource was last changed, as specified by the
 * {@code Last-Modified} header.
 * @since 5.1.4
 */
public void setIfUnmodifiedSince(ZonedDateTime ifUnmodifiedSince) {
  setZonedDateTime(IF_UNMODIFIED_SINCE, ifUnmodifiedSince.withZoneSameInstant(GMT));
}

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

/**
 * Set the time the resource was last changed, as specified by the
 * {@code Last-Modified} header.
 * @since 5.1.4
 */
public void setIfModifiedSince(ZonedDateTime ifModifiedSince) {
  setZonedDateTime(IF_MODIFIED_SINCE, ifModifiedSince.withZoneSameInstant(GMT));
}

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

/**
 * Set the time the resource was last changed, as specified by the
 * {@code Last-Modified} header.
 * @since 5.1.4
 */
public void setLastModified(ZonedDateTime lastModified) {
  setZonedDateTime(LAST_MODIFIED, lastModified.withZoneSameInstant(GMT));
}

代码示例来源:origin: stackoverflow.com

ZoneId zoneId_Norway = ZoneId.of( "Europe/Oslo" );
ZonedDateTime zdt_Norway = ZonedDateTime.of( 1985 , 1 , 1 , 3 , 2 , 1 , 0 , zoneId_Norway );

ZoneId zoneId_NewYork = ZonedId.of( "America/New_York" );
ZonedDateTime zdt_NewYork = zdt_Norway.withZoneSameInstant( zoneId_NewYork );

ZonedDateTime zdt_Utc = zdt_Norway.withZoneSameInstant( ZoneOffset.UTC );  // Or, next line is similar.
Instant instant = zdt_Norway.toInstant();  // Instant is always in UTC.

LocalDate localDate_Norway = zdt_Norway.toLocalDate();

代码示例来源:origin: Graylog2/graylog2-server

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

代码示例来源:origin: org.assertj/assertj-core

private ZonedDateTime sameInstantInActualTimeZone(ZonedDateTime zonedDateTime) {
 if (zonedDateTime == null) return null; // nothing to convert in actual's TZ
 if (actual == null) return zonedDateTime; // no actual => let's keep zonedDateTime as it is.
 return zonedDateTime.withZoneSameInstant(actual.getZone());
}

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

/**
 * Set the time the resource was last changed, as specified by the
 * {@code Last-Modified} header.
 * @since 5.1.4
 */
public void setIfModifiedSince(ZonedDateTime ifModifiedSince) {
  setZonedDateTime(IF_MODIFIED_SINCE, ifModifiedSince.withZoneSameInstant(GMT));
}

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

/**
 * Set the time the resource was last changed, as specified by the
 * {@code Last-Modified} header.
 * @since 5.1.4
 */
public void setIfUnmodifiedSince(ZonedDateTime ifUnmodifiedSince) {
  setZonedDateTime(IF_UNMODIFIED_SINCE, ifUnmodifiedSince.withZoneSameInstant(GMT));
}

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

/**
 * Set the time the resource was last changed, as specified by the
 * {@code Last-Modified} header.
 * @since 5.1.4
 */
public void setLastModified(ZonedDateTime lastModified) {
  setZonedDateTime(LAST_MODIFIED, lastModified.withZoneSameInstant(GMT));
}

代码示例来源:origin: joel-costigliola/assertj-core

private ZonedDateTime sameInstantInActualTimeZone(ZonedDateTime zonedDateTime) {
 if (zonedDateTime == null) return null; // nothing to convert in actual's TZ
 if (actual == null) return zonedDateTime; // no actual => let's keep zonedDateTime as it is.
 return zonedDateTime.withZoneSameInstant(actual.getZone());
}

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

public void setTimeZone(ZoneId timeZone) {
 if (timestampTZ != null) {
  timestampTZ.setZonedDateTime(
    timestampTZ.getZonedDateTime().withZoneSameInstant(timeZone));
 }
 this.timeZone = timeZone;
}

代码示例来源:origin: blynkkk/blynk-server

public boolean isTickTime(ZonedDateTime currentDateTime) {
  LocalDate userDate = currentDateTime.withZoneSameInstant(tzName).toLocalDate();
  int dayOfWeek = userDate.getDayOfWeek().getValue();
  return ArrayUtil.contains(days, dayOfWeek);
}

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

@Override
public Object set(Object o, TimestampTZ t) {
 if (t == null) {
  return null;
 }
 ((TimestampTZ) o).setZonedDateTime(
   t.getZonedDateTime().withZoneSameInstant(((TimestampLocalTZTypeInfo) typeInfo).timeZone()));
 return o;
}

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

private DateTimeValue( ZonedDateTime value )
{
  ZoneId zone = value.getZone();
  if ( zone instanceof ZoneOffset )
  {
    this.value = value;
  }
  else
  {
    // Do a 2-way lookup of the zone to make sure we only use the new name of renamed zones
    ZoneId mappedZone = ZoneId.of( TimeZones.map( TimeZones.map( zone.getId() ) ) );
    this.value = value.withZoneSameInstant( mappedZone );
  }
  this.epochSeconds = this.value.toEpochSecond();
}

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

@Override
public Object set(Object o, TimestampLocalTZWritable t) {
 if (t == null) {
  return null;
 }
 ((TimestampTZ) o).setZonedDateTime(
   t.getTimestampTZ().getZonedDateTime().withZoneSameInstant(((TimestampLocalTZTypeInfo) typeInfo).timeZone()));
 return o;
}

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

@Override
 public TimestampTZ getPrimitiveJavaObject(Object o) {
  if (o == null) {
   return null;
  }

  TimestampTZ t = (TimestampTZ) o;
  TimestampLocalTZTypeInfo timestampTZTypeInfo = (TimestampLocalTZTypeInfo) typeInfo;
  if (!t.getZonedDateTime().getZone().equals(timestampTZTypeInfo.timeZone())) {
   t.setZonedDateTime(
     t.getZonedDateTime().withZoneSameInstant(timestampTZTypeInfo.timeZone()));
  }
  return t;
 }
}

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

@Override
public Object set(Object o, TimestampTZ t) {
 if (t == null) {
  return null;
 }
 TimestampLocalTZTypeInfo timestampTZTypeInfo = (TimestampLocalTZTypeInfo) typeInfo;
 if (!t.getZonedDateTime().getZone().equals(timestampTZTypeInfo.timeZone())) {
  t.setZonedDateTime(t.getZonedDateTime().withZoneSameInstant(timestampTZTypeInfo.timeZone()));
 }
 ((TimestampLocalTZWritable) o).set(t);
 return o;
}

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

@Override
public TimestampLocalTZWritable getPrimitiveWritableObject(Object o) {
 if (o == null) {
  return null;
 }
 TimestampTZ t = (TimestampTZ) o;
 TimestampLocalTZTypeInfo timestampTZTypeInfo = (TimestampLocalTZTypeInfo) typeInfo;
 if (!t.getZonedDateTime().getZone().equals(timestampTZTypeInfo.timeZone())) {
  t.setZonedDateTime(
    t.getZonedDateTime().withZoneSameInstant(timestampTZTypeInfo.timeZone()));
 }
 return new TimestampLocalTZWritable(t);
}

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

@Override
public TimestampTZ getPrimitiveJavaObject(Object o) {
 if (o == null) {
  return null;
 }
 TimestampTZ t = ((LazyTimestampLocalTZ) o).getWritableObject().getTimestampTZ();
 TimestampLocalTZTypeInfo timestampTZTypeInfo = (TimestampLocalTZTypeInfo) typeInfo;
 if (!t.getZonedDateTime().getZone().equals(timestampTZTypeInfo.timeZone())) {
  t.setZonedDateTime(t.getZonedDateTime().withZoneSameInstant(timestampTZTypeInfo.timeZone()));
 }
 return t;
}

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

@Override
public Object set(Object o, TimestampLocalTZWritable t) {
 if (t == null) {
  return null;
 }
 TimestampLocalTZTypeInfo timestampTZTypeInfo = (TimestampLocalTZTypeInfo) typeInfo;
 if (!t.getTimestampTZ().getZonedDateTime().getZone().equals(timestampTZTypeInfo.timeZone())) {
  t.getTimestampTZ().setZonedDateTime(
    t.getTimestampTZ().getZonedDateTime().withZoneSameInstant(timestampTZTypeInfo.timeZone()));
 }
 ((TimestampLocalTZWritable) o).set(t);
 return o;
}

相关文章

ZonedDateTime类方法