org.threeten.bp.LocalDateTime.getNano()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(113)

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

LocalDateTime.getNano介绍

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

代码示例

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Gets the nano-of-second field.
 *
 * @return the nano-of-second, from 0 to 999,999,999
 */
public int getNano() {
  return dateTime.getNano();
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Gets the nano-of-second field.
 *
 * @return the nano-of-second, from 0 to 999,999,999
 */
public int getNano() {
  return dateTime.getNano();
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Gets the nano-of-second field.
 *
 * @return the nano-of-second, from 0 to 999,999,999
 */
public int getNano() {
  return dateTime.getNano();
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Gets the nano-of-second field.
 *
 * @return the nano-of-second, from 0 to 999,999,999
 */
public int getNano() {
  return dateTime.getNano();
}

代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp

@Override
public void serialize(LocalDateTime value, JsonGenerator g, SerializerProvider provider)
  throws IOException
{
  if (useTimestamp(provider)) {
    g.writeStartArray();
    g.writeNumber(value.getYear());
    g.writeNumber(value.getMonthValue());
    g.writeNumber(value.getDayOfMonth());
    g.writeNumber(value.getHour());
    g.writeNumber(value.getMinute());
    if (value.getSecond() > 0 || value.getNano() > 0) {
      g.writeNumber(value.getSecond());
      if(value.getNano() > 0) {
        if (provider.isEnabled(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS))
          g.writeNumber(value.getNano());
        else
          g.writeNumber(value.get(ChronoField.MILLI_OF_SECOND));
      }
    }
    g.writeEndArray();
  } else {
    DateTimeFormatter dtf = _formatter;
    if (dtf == null) {
      dtf = _defaultFormatter();
    }
    g.writeString(value.format(dtf));
  }
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Obtains an instance defining a transition between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param transition  the transition date-time at the transition, which never
 *  actually occurs, expressed local to the before offset, not null
 * @param offsetBefore  the offset before the transition, not null
 * @param offsetAfter  the offset at and after the transition, not null
 * @return the transition, not null
 * @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter}
 *         are equal, or {@code transition.getNano()} returns non-zero value
 */
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
  Jdk8Methods.requireNonNull(transition, "transition");
  Jdk8Methods.requireNonNull(offsetBefore, "offsetBefore");
  Jdk8Methods.requireNonNull(offsetAfter, "offsetAfter");
  if (offsetBefore.equals(offsetAfter)) {
    throw new IllegalArgumentException("Offsets must not be equal");
  }
  if (transition.getNano() != 0) {
    throw new IllegalArgumentException("Nano-of-second must be zero");
  }
  return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Obtains an instance defining a transition between two offsets.
 * <p>
 * Applications should normally obtain an instance from {@link ZoneRules}.
 * This factory is only intended for use when creating {@link ZoneRules}.
 *
 * @param transition  the transition date-time at the transition, which never
 *  actually occurs, expressed local to the before offset, not null
 * @param offsetBefore  the offset before the transition, not null
 * @param offsetAfter  the offset at and after the transition, not null
 * @return the transition, not null
 * @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter}
 *         are equal, or {@code transition.getNano()} returns non-zero value
 */
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
  Jdk8Methods.requireNonNull(transition, "transition");
  Jdk8Methods.requireNonNull(offsetBefore, "offsetBefore");
  Jdk8Methods.requireNonNull(offsetAfter, "offsetAfter");
  if (offsetBefore.equals(offsetAfter)) {
    throw new IllegalArgumentException("Offsets must not be equal");
  }
  if (transition.getNano() != 0) {
    throw new IllegalArgumentException("Nano-of-second must be zero");
  }
  return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Converts a {@code LocalDateTime} to a {@code java.sql.Timestamp}.
 *
 * @param dateTime  the local date-time, not null
 * @return the SQL timestamp, not null
 */
@SuppressWarnings("deprecation")
public static Timestamp toSqlTimestamp(LocalDateTime dateTime) {
  return new Timestamp(
      dateTime.getYear() - 1900,
      dateTime.getMonthValue() - 1,
      dateTime.getDayOfMonth(),
      dateTime.getHour(),
      dateTime.getMinute(),
      dateTime.getSecond(),
      dateTime.getNano());
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Converts a {@code LocalDateTime} to a {@code java.sql.Timestamp}.
 *
 * @param dateTime  the local date-time, not null
 * @return the SQL timestamp, not null
 */
@SuppressWarnings("deprecation")
public static Timestamp toSqlTimestamp(LocalDateTime dateTime) {
  return new Timestamp(
      dateTime.getYear() - 1900,
      dateTime.getMonthValue() - 1,
      dateTime.getDayOfMonth(),
      dateTime.getHour(),
      dateTime.getMinute(),
      dateTime.getSecond(),
      dateTime.getNano());
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this date-time with a different time-zone,
 * retaining the instant.
 * <p>
 * This method changes the time-zone and retains the instant.
 * This normally results in a change to the local date-time.
 * <p>
 * This method is based on retaining the same instant, thus gaps and overlaps
 * in the local time-line have no effect on the result.
 * <p>
 * To change the offset while keeping the local time,
 * use {@link #withZoneSameLocal(ZoneId)}.
 *
 * @param zone  the time-zone to change to, not null
 * @return a {@code ZonedDateTime} based on this date-time with the requested zone, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
@Override
public ZonedDateTime withZoneSameInstant(ZoneId zone) {
  Jdk8Methods.requireNonNull(zone, "zone");
  return this.zone.equals(zone) ? this :
    create(dateTime.toEpochSecond(offset), dateTime.getNano(), zone);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this date-time with a different time-zone,
 * retaining the instant.
 * <p>
 * This method changes the time-zone and retains the instant.
 * This normally results in a change to the local date-time.
 * <p>
 * This method is based on retaining the same instant, thus gaps and overlaps
 * in the local time-line have no effect on the result.
 * <p>
 * To change the offset while keeping the local time,
 * use {@link #withZoneSameLocal(ZoneId)}.
 *
 * @param zone  the time-zone to change to, not null
 * @return a {@code ZonedDateTime} based on this date-time with the requested zone, not null
 * @throws DateTimeException if the result exceeds the supported date range
 */
@Override
public ZonedDateTime withZoneSameInstant(ZoneId zone) {
  Jdk8Methods.requireNonNull(zone, "zone");
  return this.zone.equals(zone) ? this :
    create(dateTime.toEpochSecond(offset), dateTime.getNano(), zone);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Obtains an instance of {@code ZonedDateTime} from the instant formed by combining
 * the local date-time and offset.
 * <p>
 * This creates a zoned date-time by {@link LocalDateTime#toInstant(ZoneOffset) combining}
 * the {@code LocalDateTime} and {@code ZoneOffset}.
 * This combination uniquely specifies an instant without ambiguity.
 * <p>
 * Converting an instant to a zoned date-time is simple as there is only one valid
 * offset for each instant. If the valid offset is different to the offset specified,
 * the the date-time and offset of the zoned date-time will differ from those specified.
 * <p>
 * If the {@code ZoneId} to be used is a {@code ZoneOffset}, this method is equivalent
 * to {@link #of(LocalDateTime, ZoneId)}.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
  Jdk8Methods.requireNonNull(localDateTime, "localDateTime");
  Jdk8Methods.requireNonNull(offset, "offset");
  Jdk8Methods.requireNonNull(zone, "zone");
  return create(localDateTime.toEpochSecond(offset), localDateTime.getNano(), zone);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Obtains an instance of {@code ZonedDateTime} from the instant formed by combining
 * the local date-time and offset.
 * <p>
 * This creates a zoned date-time by {@link LocalDateTime#toInstant(ZoneOffset) combining}
 * the {@code LocalDateTime} and {@code ZoneOffset}.
 * This combination uniquely specifies an instant without ambiguity.
 * <p>
 * Converting an instant to a zoned date-time is simple as there is only one valid
 * offset for each instant. If the valid offset is different to the offset specified,
 * the the date-time and offset of the zoned date-time will differ from those specified.
 * <p>
 * If the {@code ZoneId} to be used is a {@code ZoneOffset}, this method is equivalent
 * to {@link #of(LocalDateTime, ZoneId)}.
 *
 * @param localDateTime  the local date-time, not null
 * @param offset  the zone offset, not null
 * @param zone  the time-zone, not null
 * @return the zoned date-time, not null
 */
public static ZonedDateTime ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
  Jdk8Methods.requireNonNull(localDateTime, "localDateTime");
  Jdk8Methods.requireNonNull(offset, "offset");
  Jdk8Methods.requireNonNull(zone, "zone");
  return create(localDateTime.toEpochSecond(offset), localDateTime.getNano(), zone);
}

代码示例来源: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);

相关文章