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

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

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

ZonedDateTime.getZone介绍

[英]Gets the time-zone, such as 'Europe/Paris'.

This returns the zone ID. This identifies the time-zone ZoneRulesthat determine when and how the offset from UTC/Greenwich changes.

The zone ID may be same as the #getOffset(). If this is true, then any future calculations, such as addition or subtraction, have no complex edge cases due to time-zone rules. See also #withFixedOffsetZone().
[中]获取时区,例如“欧洲/巴黎”。
这将返回区域ID。它标识时区区域,确定UTC/格林威治的偏移量何时以及如何变化。
区域ID可能与#getOffset()相同。如果这是真的,那么任何未来的计算,例如加法或减法,都不会因为时区规则而出现复杂的边缘情况。另请参见#withFixedOffsetZone()。

代码示例

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

@Override
ZoneId getZoneId( Supplier<ZoneId> defaultZone )
{
  return value.getZone();
}

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

@Override
ZoneId getZoneId()
{
  return value.getZone();
}

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

@JsonProperty
public ZoneId getTimeZone()
{
  return date.getZone();
}

代码示例来源: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: prestodb/presto

@Override
public Atop create(AtopTable table, ZonedDateTime date)
{
  checkArgument(date.getZone().getRules().equals(timeZone.getRules()), "Split date (%s) is not in the local timezone (%s)", date.getZone(), timeZone);
  ProcessBuilder processBuilder = new ProcessBuilder(executablePath);
  processBuilder.command().add("-P");
  processBuilder.command().add(table.getAtopLabel());
  processBuilder.command().add("-r");
  processBuilder.command().add(DATE_FORMATTER.format(date));
  Process process;
  try {
    process = processBuilder.start();
  }
  catch (IOException e) {
    throw new PrestoException(ATOP_CANNOT_START_PROCESS_ERROR, format("Cannot start %s", processBuilder.command()), e);
  }
  return new AtopProcess(process, readTimeout, executor);
}

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

@Override
protected DateTime evaluate(FunctionArgs args, EvaluationContext context, DateTimeZone timezone) {
  final Object datish = value.required(args, context);
  if (datish instanceof DateTime) {
    return (DateTime) datish;
  }
  if (datish instanceof Date) {
    return new DateTime(datish);
  }
  if (datish instanceof ZonedDateTime) {
    final ZonedDateTime zonedDateTime = (ZonedDateTime) datish;
    final DateTimeZone timeZone = DateTimeZone.forID(zonedDateTime.getZone().getId());
    return new DateTime(zonedDateTime.toInstant().toEpochMilli(), timeZone);
  }
  return null;
}

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

public void set(TimestampTZ tstz) {
 if (tstz == null) {
  timestampTZ.setZonedDateTime(null);
  return;
 }
 timestampTZ = tstz;
 timeZone = timestampTZ.getZonedDateTime().getZone();
 bytesEmpty = true;
 timestampTZEmpty = false;
}

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

public Clock at( ZonedDateTime datetime )
{
  return fixed( datetime.toInstant(), datetime.getZone() );
}

代码示例来源: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: neo4j/neo4j

private static ZoneId timezone( TemporalValue<?,?> temporal )
{
  if ( temporal instanceof DateTimeValue )
  {
    return ((DateTimeValue) temporal).temporal().getZone();
  }
  if ( temporal instanceof TimeValue )
  {
    return ((TimeValue) temporal).temporal().getOffset();
  }
  return null;
}

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

@Override
public final void writeDateTime( ZonedDateTime zonedDateTime ) throws E
{
  long epochSecondUTC = zonedDateTime.toEpochSecond();
  int nano = zonedDateTime.getNano();
  ZoneId zone = zonedDateTime.getZone();
  if ( zone instanceof ZoneOffset )
  {
    int offsetSeconds = ((ZoneOffset) zone).getTotalSeconds();
    writeDateTime( epochSecondUTC, nano, offsetSeconds );
  }
  else
  {
    String zoneId = zone.getId();
    writeDateTime( epochSecondUTC, nano, zoneId );
  }
}

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

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

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

@Override
public void write(Kryo kryo, Output output, TimestampTZ object) {
 output.writeLong(object.getEpochSecond());
 output.writeInt(object.getNanos());
 output.writeString(object.getZonedDateTime().getZone().getId());
}

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

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

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

@Test
  public void testSerialization()
  {
    JsonCodec<AtopSplit> codec = JsonCodec.jsonCodec(AtopSplit.class);
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("+01:23"));
    AtopSplit split = new AtopSplit(AtopTable.DISKS, HostAddress.fromParts("localhost", 123), now.toEpochSecond(), now.getZone());
    AtopSplit decoded = codec.fromJson(codec.toJson(split));
    assertEquals(decoded.getTable(), split.getTable());
    assertEquals(decoded.getHost(), split.getHost());
    assertEquals(decoded.getDate(), split.getDate());
    assertEquals(decoded.getEpochSeconds(), split.getEpochSeconds());
    assertEquals(decoded.getTimeZone(), split.getTimeZone());
  }
}

代码示例来源: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;
}

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

@Override
  public ConnectorSplitSource getSplits(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorTableLayoutHandle layoutHandle, SplitSchedulingStrategy splitSchedulingStrategy)
  {
    AtopTableLayoutHandle handle = (AtopTableLayoutHandle) layoutHandle;

    AtopTableHandle table = handle.getTableHandle();

    List<ConnectorSplit> splits = new ArrayList<>();
    ZonedDateTime end = ZonedDateTime.now(timeZone);
    for (Node node : nodeManager.getWorkerNodes()) {
      ZonedDateTime start = end.minusDays(maxHistoryDays - 1).withHour(0).withMinute(0).withSecond(0).withNano(0);
      while (start.isBefore(end)) {
        ZonedDateTime splitEnd = start.withHour(23).withMinute(59).withSecond(59).withNano(0);
        Domain splitDomain = Domain.create(ValueSet.ofRanges(Range.range(TIMESTAMP_WITH_TIME_ZONE, 1000 * start.toEpochSecond(), true, 1000 * splitEnd.toEpochSecond(), true)), false);
        if (handle.getStartTimeConstraint().overlaps(splitDomain) && handle.getEndTimeConstraint().overlaps(splitDomain)) {
          splits.add(new AtopSplit(table.getTable(), node.getHostAndPort(), start.toEpochSecond(), start.getZone()));
        }
        start = start.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
      }
    }

    return new FixedSplitSource(splits);
  }
}

相关文章

ZonedDateTime类方法