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

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

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

OffsetDateTime.toLocalDateTime介绍

[英]Gets the LocalDateTime part of this offset date-time.

This returns a LocalDateTime with the same year, month, day and time as this date-time.
[中]获取此偏移日期时间的LocalDateTime部分。
这将返回一个LocalDateTime,其年、月、日和时间与此日期时间相同。

代码示例

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

@Override
  public LocalDateTime convert(OffsetDateTime source) {
    return source.toLocalDateTime();
  }
}

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

@Override
  public LocalDateTime convert(OffsetDateTime source) {
    return source.toLocalDateTime();
  }
}

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

/**
 * Best effort parsing of the given value
 */
public static LocalDateTime parseBest(String value) {
 TemporalAccessor parsed = getDateTimeFormatter().parse(value);
 LocalDate datePart;
 LocalTime timePart;
 ZoneOffset zoneOffset;
 long epochDay = 0, nanoSeconds = 0;
 int offsetSeconds = 0;
 // get different parsed parts
 if (parsed.isSupported(ChronoField.EPOCH_DAY)) {
  epochDay = parsed.getLong(ChronoField.EPOCH_DAY);
 }
 if (parsed.isSupported(ChronoField.NANO_OF_DAY)) {
  nanoSeconds = parsed.getLong(ChronoField.NANO_OF_DAY);
 }
 if (parsed.isSupported(ChronoField.OFFSET_SECONDS)) {
  offsetSeconds = parsed.get(ChronoField.OFFSET_SECONDS);
 }
 zoneOffset = ZoneOffset.ofTotalSeconds(offsetSeconds);
 datePart = LocalDate.ofEpochDay(epochDay);
 timePart = LocalTime.ofNanoOfDay(nanoSeconds);
 return OffsetDateTime.of(datePart, timePart, zoneOffset).toLocalDateTime();
}

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

@Override
  public LocalDateTime convert(OffsetDateTime source) {
    return source.toLocalDateTime();
  }
}

代码示例来源:origin: owlike/genson

static OffsetDateTime correctOffset(OffsetDateTime value, ZoneId zoneId) {
    Instant instant = value.toLocalDateTime().atZone(zoneId).toInstant();
    return OffsetDateTime.ofInstant(instant, zoneId);
  }
}

代码示例来源:origin: org.jadira.usertype/usertype.core

@Override
protected Object[] toConvertedColumns(OffsetDateTime value) {
  return new Object[] { value.toLocalDateTime(), value.getOffset() };
}

代码示例来源:origin: org.jadira.usertype/usertype.extended

@Override
protected Object[] toConvertedColumns(OffsetDateTime value) {
  return new Object[] { value.toLocalDateTime(), value.getOffset() };
}

代码示例来源:origin: com.sqlapp/sqlapp-core

protected ZonedDateTime toZonedDateTime(OffsetDateTime date){
  return ZonedDateTime.of(date.toLocalDateTime(), date.getOffset());
}

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

String dateTimestr = "2015-02-05T02:05:17.000+00:00";

OffsetDateTime dateTime = OffsetDateTime.parse(dateTimestr);

if ((dateTime.getNano() == 0) && (dateTimestr.length() > 25 ))
  System.out.println(dateTime.toLocalDateTime() + ".000Z");

else
  System.out.println(dateTime.toString());

代码示例来源:origin: de.juplo/jpa-converters

@Override
public Timestamp convertToDatabaseColumn(OffsetDateTime odt)
{
 if (odt == null)
  return null;
 return Timestamp.valueOf(odt.withOffsetSameInstant(TimeConversions.getZoneOffset()).toLocalDateTime());
}

代码示例来源:origin: Netflix/iceberg

@Override
 public LocalDateTime read(LocalDateTime reuse) {
  return EPOCH.plus(column.nextLong(), ChronoUnit.MICROS).toLocalDateTime();
 }
}

代码示例来源:origin: Netflix/iceberg

@Override
 public LocalDateTime read(LocalDateTime reuse) {
  return EPOCH.plus(column.nextLong() * 1000, ChronoUnit.MICROS).toLocalDateTime();
 }
}

代码示例来源:origin: Netflix/iceberg

@Override
 public LocalDateTime read(Decoder decoder, Object reuse) throws IOException {
  return EPOCH.plus(decoder.readLong(), ChronoUnit.MICROS).toLocalDateTime();
 }
}

代码示例来源:origin: Netflix/iceberg

static String humanTimestampWithoutZone(Long timestampMicros) {
 return ChronoUnit.MICROS.addTo(EPOCH, timestampMicros).toLocalDateTime().toString();
}

代码示例来源: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.apache.tinkerpop/gremlin-core

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

相关文章