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

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

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

  1. /**
  2. * Returns true if both OffsetDateTime are in the same nanosecond, false otherwise.
  3. *
  4. * @param actual the actual OffsetDateTime. expected not be null
  5. * @param other the other OffsetDateTime. expected not be null
  6. * @return true if both OffsetDateTime are in the same year, false otherwise
  7. */
  8. private static boolean haveSameNano(OffsetDateTime actual, OffsetDateTime other) {
  9. return actual.getNano() == other.getNano();
  10. }

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

  1. /**
  2. * Returns true if both OffsetDateTime are in the same nanosecond, false otherwise.
  3. *
  4. * @param actual the actual OffsetDateTime. expected not be null
  5. * @param other the other OffsetDateTime. expected not be null
  6. * @return true if both OffsetDateTime are in the same year, false otherwise
  7. */
  8. private static boolean haveSameNano(OffsetDateTime actual, OffsetDateTime other) {
  9. return actual.getNano() == other.getNano();
  10. }

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

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

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

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

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

  1. @Override
  2. public Timestamp toNonNullValue(OffsetDateTime value) {
  3. final Timestamp timestamp = new Timestamp((value.toEpochSecond() * MILLIS_IN_SECOND));
  4. timestamp.setNanos(value.getNano());
  5. return timestamp;
  6. }

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

  1. @Override
  2. public Timestamp toNonNullValue(OffsetDateTime value) {
  3. final Timestamp timestamp = new Timestamp((value.toEpochSecond() * MILLIS_IN_SECOND));
  4. timestamp.setNanos(value.getNano());
  5. return timestamp;
  6. }

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

  1. String dateTimestr = "2015-02-05T02:05:17.000+00:00";
  2. OffsetDateTime dateTime = OffsetDateTime.parse(dateTimestr);
  3. if ((dateTime.getNano() == 0) && (dateTimestr.length() > 25 ))
  4. System.out.println(dateTime.toLocalDateTime() + ".000Z");
  5. else
  6. System.out.println(dateTime.toString());

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

  1. /**
  2. * Converts the given OffsetDateTime to a Timestamp.
  3. *
  4. * @param offsetDateTime
  5. * the OffsetDateTime to convert
  6. * @return Timestamp object that is equivalent to the given OffsetDateTime.
  7. */
  8. private static Timestamp toTimestamp(OffsetDateTime offsetDateTime) {
  9. long seconds = offsetDateTime.toEpochSecond();
  10. int nanos = offsetDateTime.getNano();
  11. long microseconds = TimeUnit.SECONDS.toMicros(seconds) + TimeUnit.NANOSECONDS.toMicros(nanos);
  12. return Timestamp.ofTimeMicroseconds(microseconds);
  13. }

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

  1. @Override
  2. public int compare(OffsetDateTime datetime1, OffsetDateTime datetime2) {
  3. int cmp = Jdk8Methods.compareLongs(datetime1.toEpochSecond(), datetime2.toEpochSecond());
  4. if (cmp == 0) {
  5. cmp = Jdk8Methods.compareLongs(datetime1.getNano(), datetime2.getNano());
  6. }
  7. return cmp;
  8. }
  9. };

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

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

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

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

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

  1. @Override
  2. public ValueBuilder<?, ?, ?> toDatastore(Object input) {
  3. if (input == null) {
  4. return NullValue.newBuilder();
  5. }
  6. OffsetDateTime offsetDateTime = (OffsetDateTime) input;
  7. long seconds = offsetDateTime.toEpochSecond();
  8. int nanos = offsetDateTime.getNano();
  9. long microseconds = TimeUnit.SECONDS.toMicros(seconds) + TimeUnit.NANOSECONDS.toMicros(nanos);
  10. return TimestampValue.newBuilder(Timestamp.ofTimeMicroseconds(microseconds));
  11. }

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

  1. @Override
  2. protected void encodeValue(Context context, Type type, Object value, Object sourceContext, ByteBuf buffer) throws IOException {
  3. Calendar calendar = sourceContext != null ? (Calendar) sourceContext : Calendar.getInstance();
  4. OffsetDateTime dateTime = convertInput(context, type, value, calendar);
  5. long micros;
  6. if (dateTime.equals(OffsetDateTime.MAX)) {
  7. micros = Long.MAX_VALUE;
  8. }
  9. else if (dateTime.equals(OffsetDateTime.MIN)) {
  10. micros = Long.MIN_VALUE;
  11. }
  12. else {
  13. long seconds = javaEpochToPg(dateTime.toEpochSecond(), SECONDS);
  14. // Convert to micros rounding nanoseconds
  15. micros = SECONDS.toMicros(seconds) + NANOSECONDS.toMicros(dateTime.getNano() + 500);
  16. }
  17. buffer.writeLong(micros);
  18. }

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

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

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

  1. @Override
  2. public final void serialize(Writer writer, OffsetDateTime datetime) throws IOException {
  3. super.serialize(writer, datetime);
  4. OutputStream stream = writer.stream;
  5. if (!(datetime.getOffset().equals(ZoneOffset.UTC))) {
  6. stream.write(TagString);
  7. ValueWriter.write(stream, datetime.toString());
  8. }
  9. else {
  10. int year = datetime.getYear();
  11. if (year > 9999 || year < 1) {
  12. stream.write(TagString);
  13. ValueWriter.write(stream, datetime.toString());
  14. }
  15. else {
  16. ValueWriter.writeDate(stream, year, datetime.getMonthValue(), datetime.getDayOfMonth());
  17. ValueWriter.writeTime(stream, datetime.getHour(), datetime.getMinute(), datetime.getSecond(), 0, false, true);
  18. ValueWriter.writeNano(stream, datetime.getNano());
  19. stream.write(TagUTC);
  20. }
  21. }
  22. }
  23. }

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

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

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

  1. @Override
  2. public final void serialize(Writer writer, OffsetDateTime datetime) throws IOException {
  3. super.serialize(writer, datetime);
  4. OutputStream stream = writer.stream;
  5. if (!(datetime.getOffset().equals(ZoneOffset.UTC))) {
  6. stream.write(TagString);
  7. ValueWriter.write(stream, datetime.toString());
  8. }
  9. else {
  10. int year = datetime.getYear();
  11. if (year > 9999 || year < 1) {
  12. stream.write(TagString);
  13. ValueWriter.write(stream, datetime.toString());
  14. }
  15. else {
  16. ValueWriter.writeDate(stream, year, datetime.getMonthValue(), datetime.getDayOfMonth());
  17. ValueWriter.writeTime(stream, datetime.getHour(), datetime.getMinute(), datetime.getSecond(), 0, false, true);
  18. ValueWriter.writeNano(stream, datetime.getNano());
  19. stream.write(TagUTC);
  20. }
  21. }
  22. }
  23. }

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

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

相关文章