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

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

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

OffsetDateTime.getNano介绍

[英]Gets the nano-of-second field.
[中]获取第二个字段的nano。

代码示例

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

/**
 * Returns true if both OffsetDateTime are in the same nanosecond, false otherwise.
 *
 * @param actual the actual OffsetDateTime. expected not be null
 * @param other the other OffsetDateTime. expected not be null
 * @return true if both OffsetDateTime are in the same year, false otherwise
 */
private static boolean haveSameNano(OffsetDateTime actual, OffsetDateTime other) {
 return actual.getNano() == other.getNano();
}

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

/**
 * Returns true if both OffsetDateTime are in the same nanosecond, false otherwise.
 *
 * @param actual the actual OffsetDateTime. expected not be null
 * @param other the other OffsetDateTime. expected not be null
 * @return true if both OffsetDateTime are in the same year, false otherwise
 */
private static boolean haveSameNano(OffsetDateTime actual, OffsetDateTime other) {
 return actual.getNano() == other.getNano();
}

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

@Override
protected String toJsonNanos(OffsetDateTime value) {
 return toJsonNanos(value.toEpochSecond(), value.getNano());
}

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

assertThat(c4DateTime.getMinute()).isEqualTo(0);
  assertThat(c4DateTime.getSecond()).isEqualTo(0);
  assertThat(c4DateTime.getNano()).isEqualTo(0);
} else if (record.topic().endsWith("dbz_123_bitvaluetest")) {

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

@Override
public Timestamp toNonNullValue(OffsetDateTime value) {
  
  final Timestamp timestamp = new Timestamp((value.toEpochSecond() * MILLIS_IN_SECOND));
  timestamp.setNanos(value.getNano());
  return timestamp;
}

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

@Override
public Timestamp toNonNullValue(OffsetDateTime value) {
  
  final Timestamp timestamp = new Timestamp((value.toEpochSecond() * MILLIS_IN_SECOND));
  timestamp.setNanos(value.getNano());
  return timestamp;
}

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

/**
 * Converts the given OffsetDateTime to a Timestamp.
 * 
 * @param offsetDateTime
 *          the OffsetDateTime to convert
 * @return Timestamp object that is equivalent to the given OffsetDateTime.
 */
private static Timestamp toTimestamp(OffsetDateTime offsetDateTime) {
 long seconds = offsetDateTime.toEpochSecond();
 int nanos = offsetDateTime.getNano();
 long microseconds = TimeUnit.SECONDS.toMicros(seconds) + TimeUnit.NANOSECONDS.toMicros(nanos);
 return Timestamp.ofTimeMicroseconds(microseconds);
}

代码示例来源:origin: com.github.seratch/java-time-backport

@Override
  public int compare(OffsetDateTime datetime1, OffsetDateTime datetime2) {
    int cmp = Jdk8Methods.compareLongs(datetime1.toEpochSecond(), datetime2.toEpochSecond());
    if (cmp == 0) {
      cmp = Jdk8Methods.compareLongs(datetime1.getNano(), datetime2.getNano());
    }
    return cmp;
  }
};

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

@Override
protected String toJsonNanos(OffsetDateTime value) {
 return toJsonNanos(value.toEpochSecond(), value.getNano());
}

代码示例来源:origin: org.avaje.ebean/ebean

@Override
protected String toJsonNanos(OffsetDateTime value) {
 return toJsonNanos(value.toEpochSecond(), value.getNano());
}

代码示例来源:origin: sai-pullabhotla/catatumbo

@Override
public ValueBuilder<?, ?, ?> toDatastore(Object input) {
 if (input == null) {
  return NullValue.newBuilder();
 }
 OffsetDateTime offsetDateTime = (OffsetDateTime) input;
 long seconds = offsetDateTime.toEpochSecond();
 int nanos = offsetDateTime.getNano();
 long microseconds = TimeUnit.SECONDS.toMicros(seconds) + TimeUnit.NANOSECONDS.toMicros(nanos);
 return TimestampValue.newBuilder(Timestamp.ofTimeMicroseconds(microseconds));
}

代码示例来源:origin: com.impossibl.pgjdbc-ng/pgjdbc-ng

@Override
protected void encodeValue(Context context, Type type, Object value, Object sourceContext, ByteBuf buffer) throws IOException {
 Calendar calendar = sourceContext != null ? (Calendar) sourceContext : Calendar.getInstance();
 OffsetDateTime dateTime = convertInput(context, type, value, calendar);
 long micros;
 if (dateTime.equals(OffsetDateTime.MAX)) {
  micros = Long.MAX_VALUE;
 }
 else if (dateTime.equals(OffsetDateTime.MIN)) {
  micros = Long.MIN_VALUE;
 }
 else {
  long seconds = javaEpochToPg(dateTime.toEpochSecond(), SECONDS);
  // Convert to micros rounding nanoseconds
  micros = SECONDS.toMicros(seconds) + NANOSECONDS.toMicros(dateTime.getNano() + 500);
 }
 buffer.writeLong(micros);
}

代码示例来源:origin: kiegroup/optaweb-employee-rostering

public static LocalDateTime toLocalDateTimeInZone(OffsetDateTime dateTime, ZoneId zoneId) {
  return LocalDateTime.ofEpochSecond(dateTime.toEpochSecond(), dateTime.getNano(),
                    zoneId.getRules().getOffset(dateTime.toInstant()));
}

代码示例来源:origin: hprose/hprose-java

@Override
  public final void serialize(Writer writer, OffsetDateTime datetime) throws IOException {
    super.serialize(writer, datetime);
    OutputStream stream = writer.stream;
    if (!(datetime.getOffset().equals(ZoneOffset.UTC))) {
      stream.write(TagString);
      ValueWriter.write(stream, datetime.toString());
    }
    else {
      int year = datetime.getYear();
      if (year > 9999 || year < 1) {
        stream.write(TagString);
        ValueWriter.write(stream, datetime.toString());
      }
      else {
        ValueWriter.writeDate(stream, year, datetime.getMonthValue(), datetime.getDayOfMonth());
        ValueWriter.writeTime(stream, datetime.getHour(), datetime.getMinute(), datetime.getSecond(), 0, false, true);
        ValueWriter.writeNano(stream, datetime.getNano());
        stream.write(TagUTC);
      }
    }
  }
}

代码示例来源:origin: com.github.seratch/java-time-backport

ChronoField f = (ChronoField) field;
switch (f) {
  case INSTANT_SECONDS: return ofInstant(Instant.ofEpochSecond(newValue, getNano()), offset);
  case OFFSET_SECONDS: {
    return with(dateTime, ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue)));

代码示例来源:origin: org.hprose/hprose-java

@Override
  public final void serialize(Writer writer, OffsetDateTime datetime) throws IOException {
    super.serialize(writer, datetime);
    OutputStream stream = writer.stream;
    if (!(datetime.getOffset().equals(ZoneOffset.UTC))) {
      stream.write(TagString);
      ValueWriter.write(stream, datetime.toString());
    }
    else {
      int year = datetime.getYear();
      if (year > 9999 || year < 1) {
        stream.write(TagString);
        ValueWriter.write(stream, datetime.toString());
      }
      else {
        ValueWriter.writeDate(stream, year, datetime.getMonthValue(), datetime.getDayOfMonth());
        ValueWriter.writeTime(stream, datetime.getHour(), datetime.getMinute(), datetime.getSecond(), 0, false, true);
        ValueWriter.writeNano(stream, datetime.getNano());
        stream.write(TagUTC);
      }
    }
  }
}

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

buf[pos + 17] = ':';
NumberConverter.write2(value.getSecond(), buf, pos + 18);
final int nano = value.getNano();
if (nano != 0) {
  final int end = writeNano(buf, pos, nano);

相关文章