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

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

本文整理了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

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

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

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

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

  1. /**
  2. * Applies local time zone offset to timestamp value read using specified {@code reader}.
  3. *
  4. * @param writer writer to store string representation of timestamp value
  5. * @param fieldName name of the field
  6. * @param reader document reader
  7. */
  8. @Override
  9. protected void writeTimeStamp(MapOrListWriterImpl writer, String fieldName, DocumentReader reader) {
  10. String formattedTimestamp = Instant.ofEpochMilli(reader.getTimestampLong())
  11. .atOffset(OffsetDateTime.now().getOffset()).format(DateUtility.UTC_FORMATTER);
  12. writeString(writer, fieldName, formattedTimestamp);
  13. }
  14. };

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

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

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

  1. public synchronized String toString(OffsetDateTime offsetDateTime) {
  2. if (offsetDateTime.isAfter(MAX_OFFSET_DATETIME)) {
  3. return "infinity";
  4. } else if (OffsetDateTime.MIN.equals(offsetDateTime)) {
  5. return "-infinity";
  6. }
  7. sbuf.setLength(0);
  8. int nano = offsetDateTime.getNano();
  9. if (nanosExceed499(nano)) {
  10. // Technically speaking this is not a proper rounding, however
  11. // it relies on the fact that appendTime just truncates 000..999 nanosecond part
  12. offsetDateTime = offsetDateTime.plus(ONE_MICROSECOND);
  13. }
  14. LocalDateTime localDateTime = offsetDateTime.toLocalDateTime();
  15. LocalDate localDate = localDateTime.toLocalDate();
  16. appendDate(sbuf, localDate);
  17. sbuf.append(' ');
  18. appendTime(sbuf, localDateTime.toLocalTime());
  19. appendTimeZone(sbuf, offsetDateTime.getOffset());
  20. appendEra(sbuf, localDate);
  21. return sbuf.toString();
  22. }

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

  1. private static EventDateTime getEventDateTime(CalendarEventModel.CalendarEventTime dateTime) {
  2. if (dateTime == null) {
  3. return null;
  4. }
  5. EventDateTime eventDateTime = new EventDateTime();
  6. // google's APIs want millisecond from epoch, and the timezone offset in minutes.
  7. if (dateTime.isDateOnly()) {
  8. eventDateTime.setDate(new DateTime(true,
  9. dateTime.getDateTime().toEpochSecond() * 1000,
  10. dateTime.getDateTime().getOffset().getTotalSeconds() / 60));
  11. } else {
  12. eventDateTime.setDateTime(new DateTime(
  13. dateTime.getDateTime().toEpochSecond() * 1000,
  14. dateTime.getDateTime().getOffset().getTotalSeconds() / 60));
  15. }
  16. return eventDateTime;
  17. }

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

  1. @Test
  2. public void shouldAllowCustomTimestampParameter() {
  3. Person input = new Person("John", "Phiri");
  4. input.setId(1);
  5. recordNextTimestamp("createdAt");
  6. personDAO.insertWithCustomTimestampFields(input);
  7. assertThat(insertedTimestamp.getOffset()).isEqualTo(GMT_PLUS_2);
  8. assertThat(insertedTimestamp.toInstant()).isEqualTo(UTC_MOMENT.toInstant());
  9. Person result = personDAO.get(1);
  10. assertThat(result.getFirstName()).isEqualTo(input.getFirstName());
  11. assertThat(result.getLastName()).isEqualTo(input.getLastName());
  12. assertThat(result.getCreated())
  13. .isEqualTo(result.getModified())
  14. .isEqualTo(insertedSqlTimestamp);
  15. }

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

  1. @Test
  2. public void shouldInsertCreatedAndModifiedFields() {
  3. Person input = new Person("John", "Phiri");
  4. input.setId(1);
  5. recordNextTimestamp("now");
  6. personDAO.insert(input);
  7. assertThat(insertedTimestamp.getOffset()).isEqualTo(GMT_PLUS_2);
  8. assertThat(insertedTimestamp.toInstant()).isEqualTo(UTC_MOMENT.toInstant());
  9. Person result = personDAO.get(1);
  10. assertThat(result.getCreated())
  11. .isEqualTo(result.getModified())
  12. .isEqualTo(insertedSqlTimestamp);
  13. }

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

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

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

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

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

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

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

  1. @Override
  2. public void serialize(OffsetDateTime instant, JsonGenerator generator, SerializerProvider provider)
  3. throws IOException {
  4. StringBuilder builder = new StringBuilder();
  5. builder.append(instant.toLocalDateTime().toString());
  6. if (instant.getSecond() == 0 && instant.getNano() == 0) {
  7. builder.append(":00");
  8. }
  9. builder.append(instant.getOffset().toString());
  10. generator.writeString(builder.toString());
  11. }
  12. }

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

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

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

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

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

  1. public static DateTimeOffset offsetDateTimeToDateTimeOffset(OffsetDateTime attribute) {
  2. if (attribute == null) {
  3. return null;
  4. }
  5. Timestamp timestamp = Timestamp.from(attribute.toInstant());
  6. int offsetSeconds = attribute.getOffset().getTotalSeconds();
  7. return DateTimeOffset.valueOf(timestamp, Math.toIntExact(SECONDS.toMinutes(offsetSeconds)));
  8. }

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

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

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

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

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

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

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

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

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

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

相关文章