/** * Obtains an instance of {@code ZonedDateTime} from an {@code Instant}. * <p> * This creates a zoned date-time with the same instant as that specified. * Calling {@link #toInstant()} will return an instant equal to the one used here. * <p> * Converting an instant to a zoned date-time is simple as there is only one valid * offset for each instant. * * @param instant the instant to create the date-time from, not null * @param zone the time-zone, not null * @return the zoned date-time, not null * @throws DateTimeException if the result exceeds the supported range */ public static ZonedDateTime ofInstant(Instant instant, ZoneId zone) { Jdk8Methods.requireNonNull(instant, "instant"); Jdk8Methods.requireNonNull(zone, "zone"); return create(instant.getEpochSecond(), instant.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 an {@code Instant}. * <p> * This creates a zoned date-time with the same instant as that specified. * Calling {@link #toInstant()} will return an instant equal to the one used here. * <p> * Converting an instant to a zoned date-time is simple as there is only one valid * offset for each instant. * * @param instant the instant to create the date-time from, not null * @param zone the time-zone, not null * @return the zoned date-time, not null * @throws DateTimeException if the result exceeds the supported range */ public static ZonedDateTime ofInstant(Instant instant, ZoneId zone) { Jdk8Methods.requireNonNull(instant, "instant"); Jdk8Methods.requireNonNull(zone, "zone"); return create(instant.getEpochSecond(), instant.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); }
long epochSecond = temporal.getLong(INSTANT_SECONDS); int nanoOfSecond = temporal.get(NANO_OF_SECOND); return create(epochSecond, nanoOfSecond, zone);
long epochSecond = temporal.getLong(INSTANT_SECONDS); int nanoOfSecond = temporal.get(NANO_OF_SECOND); return create(epochSecond, nanoOfSecond, 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); }
ChronoField f = (ChronoField) field; switch (f) { case INSTANT_SECONDS: return create(newValue, getNano(), zone); case OFFSET_SECONDS: { ZoneOffset offset = ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue));
ChronoField f = (ChronoField) field; switch (f) { case INSTANT_SECONDS: return create(newValue, getNano(), zone); case OFFSET_SECONDS: { ZoneOffset offset = ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue));
} else if (adjuster instanceof Instant) { Instant instant = (Instant) adjuster; return create(instant.getEpochSecond(), instant.getNano(), zone); } else if (adjuster instanceof ZoneOffset) { return resolveOffset((ZoneOffset) adjuster);
} else if (adjuster instanceof Instant) { Instant instant = (Instant) adjuster; return create(instant.getEpochSecond(), instant.getNano(), zone); } else if (adjuster instanceof ZoneOffset) { return resolveOffset((ZoneOffset) adjuster);