java.time.OffsetDateTime.getOffset()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(198)

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

OffsetDateTime.getOffset介绍

[英]Gets the zone offset, such as '+01:00'.

This is the offset of the local date-time from UTC/Greenwich.
[中]获取区域偏移量,例如“+01:00”。
这是本地日期时间与UTC/格林威治时间的偏移量。

代码示例

代码示例来源:origin: hibernate/hibernate-orm

return ( (Time) value ).toLocalTime().atOffset( OffsetDateTime.now().getOffset() );

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

public Clock at( OffsetDateTime datetime )
{
  return fixed( datetime.toInstant(), datetime.getOffset() );
}

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

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

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

private static String currentTimeZoneOffsetString()
  {
    ZoneOffset offset = OffsetDateTime.now().getOffset();
    return offset.equals( UTC ) ? "+0000" : offset.toString().replace( ":", "" );
  }
}

代码示例来源:origin: org.postgresql/postgresql

public synchronized String toString(OffsetDateTime offsetDateTime) {
 if (offsetDateTime.isAfter(MAX_OFFSET_DATETIME)) {
  return "infinity";
 } else if (OffsetDateTime.MIN.equals(offsetDateTime)) {
  return "-infinity";
 }
 sbuf.setLength(0);
 int nano = offsetDateTime.getNano();
 if (nanosExceed499(nano)) {
  // Technically speaking this is not a proper rounding, however
  // it relies on the fact that appendTime just truncates 000..999 nanosecond part
  offsetDateTime = offsetDateTime.plus(ONE_MICROSECOND);
 }
 LocalDateTime localDateTime = offsetDateTime.toLocalDateTime();
 LocalDate localDate = localDateTime.toLocalDate();
 appendDate(sbuf, localDate);
 sbuf.append(' ');
 appendTime(sbuf, localDateTime.toLocalTime());
 appendTimeZone(sbuf, offsetDateTime.getOffset());
 appendEra(sbuf, localDate);
 return sbuf.toString();
}

代码示例来源:origin: google/data-transfer-project

private static EventDateTime getEventDateTime(CalendarEventModel.CalendarEventTime dateTime) {
 if (dateTime == null) {
  return null;
 }
 EventDateTime eventDateTime = new EventDateTime();
 // google's APIs want millisecond from epoch, and the timezone offset in minutes.
 if (dateTime.isDateOnly()) {
  eventDateTime.setDate(new DateTime(true,
    dateTime.getDateTime().toEpochSecond() * 1000,
    dateTime.getDateTime().getOffset().getTotalSeconds() / 60));
 } else {
  eventDateTime.setDateTime(new DateTime(
    dateTime.getDateTime().toEpochSecond() * 1000,
    dateTime.getDateTime().getOffset().getTotalSeconds() / 60));
 }
 return eventDateTime;
}

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

@Test
public void shouldAllowCustomTimestampParameter() {
  Person input = new Person("John", "Phiri");
  input.setId(1);
  recordNextTimestamp("createdAt");
  personDAO.insertWithCustomTimestampFields(input);
  assertThat(insertedTimestamp.getOffset()).isEqualTo(GMT_PLUS_2);
  assertThat(insertedTimestamp.toInstant()).isEqualTo(UTC_MOMENT.toInstant());
  Person result = personDAO.get(1);
  assertThat(result.getFirstName()).isEqualTo(input.getFirstName());
  assertThat(result.getLastName()).isEqualTo(input.getLastName());
  assertThat(result.getCreated())
    .isEqualTo(result.getModified())
    .isEqualTo(insertedSqlTimestamp);
}

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

@Test
public void shouldInsertCreatedAndModifiedFields() {
  Person input = new Person("John", "Phiri");
  input.setId(1);
  recordNextTimestamp("now");
  personDAO.insert(input);
  assertThat(insertedTimestamp.getOffset()).isEqualTo(GMT_PLUS_2);
  assertThat(insertedTimestamp.toInstant()).isEqualTo(UTC_MOMENT.toInstant());
  Person result = personDAO.get(1);
  assertThat(result.getCreated())
    .isEqualTo(result.getModified())
    .isEqualTo(insertedSqlTimestamp);
}

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

@Override
public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final OffsetDateTime offsetDateTime) {
  kryo.writeObject(output, offsetDateTime.toLocalDateTime());
  kryo.writeObject(output, offsetDateTime.getOffset());
}

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

assertThat(c4DateTime.getOffset()).isEqualTo(ZoneOffset.UTC);

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

@Override
  protected ByteBuf writeValue(final OffsetDateTime value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException {
    final CompositeByteBuf result = allocator.compositeBuffer(2);
    result.addComponent(true, context.writeValue(value.toLocalDateTime(), allocator, false));
    result.addComponent(true, context.writeValue(value.getOffset(), allocator, false));
    return result;
  }
}

代码示例来源:origin: openmhealth/schemas

@Override
  public void serialize(OffsetDateTime instant, JsonGenerator generator, SerializerProvider provider)
      throws IOException {

    StringBuilder builder = new StringBuilder();

    builder.append(instant.toLocalDateTime().toString());

    if (instant.getSecond() == 0 && instant.getNano() == 0) {
      builder.append(":00");
    }

    builder.append(instant.getOffset().toString());

    generator.writeString(builder.toString());
  }
}

代码示例来源:origin: org.jsimpledb/jsimpledb-coreapi

@Override
public ZonedDateTime fromParseableString(ParseContext ctx) {
  final OffsetDateTime offsetDateTime = this.type1.fromParseableString(ctx);
  final Matcher matcher = ctx.tryPattern("\\[(.+)\\]");
  final ZoneId zoneId = matcher != null ? this.type2.fromString(matcher.group(1)) : offsetDateTime.getOffset();
  return ZonedDateTime.ofInstant(offsetDateTime.toInstant(), zoneId);
}

代码示例来源:origin: io.permazen/permazen-coreapi

@Override
public ZonedDateTime fromParseableString(ParseContext ctx) {
  final OffsetDateTime offsetDateTime = this.type1.fromParseableString(ctx);
  final Matcher matcher = ctx.tryPattern("\\[(.+)\\]");
  final ZoneId zoneId = matcher != null ? this.type2.fromString(matcher.group(1)) : offsetDateTime.getOffset();
  return ZonedDateTime.ofInstant(offsetDateTime.toInstant(), zoneId);
}

代码示例来源:origin: com.github.marschall/threeten-jpa-mssql-impl

public static DateTimeOffset offsetDateTimeToDateTimeOffset(OffsetDateTime attribute) {
 if (attribute == null) {
  return null;
 }
 Timestamp timestamp = Timestamp.from(attribute.toInstant());
 int offsetSeconds = attribute.getOffset().getTotalSeconds();
 return DateTimeOffset.valueOf(timestamp, Math.toIntExact(SECONDS.toMinutes(offsetSeconds)));
}

代码示例来源:origin: ngs-doo/dsl-json

private static void writeTimezone(final int position, final OffsetDateTime dt, final JsonWriter sw) {
  final ZoneOffset zone = dt.getOffset();
  sw.advance(position);
  sw.writeAscii(zone.getId());
  sw.writeByte(JsonWriter.QUOTE);
}

代码示例来源:origin: com.esotericsoftware/kryo

public void write (Kryo kryo, Output out, OffsetDateTime obj) {
  LocalDateSerializer.write(out, obj.toLocalDate());
  LocalTimeSerializer.write(out, obj.toLocalTime());
  ZoneOffsetSerializer.write(out, obj.getOffset());
}

代码示例来源:origin: com.esotericsoftware/kryo-shaded

public void write (Kryo kryo, Output out, OffsetDateTime obj) {
  LocalDateSerializer.write(out, obj.toLocalDate());
  LocalTimeSerializer.write(out, obj.toLocalTime());
  ZoneOffsetSerializer.write(out, obj.getOffset());
}

代码示例来源:origin: ru.curs/celesta-sql

@Override
public ZonedDateTime prepareZonedDateTimeForParameterSetter(Connection conn, ZonedDateTime z) {
  ZoneOffset systemOffset = OffsetDateTime.now().getOffset();
  ZoneOffset offset = z.getOffset();
  int offsetDifInSeconds = systemOffset.getTotalSeconds() - offset.getTotalSeconds();
  return z.plusSeconds(offsetDifInSeconds);
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-driver

@Override
  public ByteBuf writeValue(final OffsetDateTime value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException {
    final CompositeByteBuf result = allocator.compositeBuffer(2);
    result.addComponent(true, context.writeValue(value.toLocalDateTime(), allocator, false));
    result.addComponent(true, context.writeValue(value.getOffset(), allocator, false));
    return result;
  }
}

相关文章