/** * Gets the nano-of-second field. * * @return the nano-of-second, from 0 to 999,999,999 */ public int getNano() { return dateTime.getNano(); }
/** * Gets the nano-of-second field. * * @return the nano-of-second, from 0 to 999,999,999 */ public int getNano() { return dateTime.getNano(); }
/** * Gets the nano-of-second field. * * @return the nano-of-second, from 0 to 999,999,999 */ public int getNano() { return dateTime.getNano(); }
/** * Gets the nano-of-second field. * * @return the nano-of-second, from 0 to 999,999,999 */ public int getNano() { return dateTime.getNano(); }
@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)); } }
/** * 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); }
/** * 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); }
/** * 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()); }
/** * 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()); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
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);