/** * Combines this instant with an offset to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this instant at the * specified offset from UTC/Greenwich. An exception will be thrown if the * instant is too large to fit into an offset date-time. * <p> * This method is equivalent to * {@link OffsetDateTime#ofInstant(Instant, ZoneId) OffsetDateTime.ofInstant(this, offset)}. * * @param offset the offset to combine with, not null * @return the offset date-time formed from this instant and the specified offset, not null * @throws DateTimeException if the result exceeds the supported range */ public OffsetDateTime atOffset(ZoneOffset offset) { return OffsetDateTime.ofInstant(this, offset); }
/** * Combines this instant with an offset to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this instant at the * specified offset from UTC/Greenwich. An exception will be thrown if the * instant is too large to fit into an offset date-time. * <p> * This method is equivalent to * {@link OffsetDateTime#ofInstant(Instant, ZoneId) OffsetDateTime.ofInstant(this, offset)}. * * @param offset the offset to combine with, not null * @return the offset date-time formed from this instant and the specified offset, not null * @throws DateTimeException if the result exceeds the supported range */ public OffsetDateTime atOffset(ZoneOffset offset) { return OffsetDateTime.ofInstant(this, offset); }
@Override public OffsetDateTime apply(FromIntegerArguments a) { return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); } },
@Override public OffsetDateTime apply(FromIntegerArguments a) { return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); } },
@Override public OffsetDateTime apply(FromDecimalArguments a) { return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); } },
@Override public OffsetDateTime apply(FromIntegerArguments a) { return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); } },
@Override public OffsetDateTime apply(FromDecimalArguments a) { return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); } },
@Override public OffsetDateTime apply(FromIntegerArguments a) { return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); } },
@Override public OffsetDateTime apply(FromDecimalArguments a) { return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); } },
@Override public OffsetDateTime apply(FromDecimalArguments a) { return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); } },
} catch (DateTimeException ignore) { Instant instant = Instant.from(temporal); return OffsetDateTime.ofInstant(instant, offset);
} catch (DateTimeException ignore) { Instant instant = Instant.from(temporal); return OffsetDateTime.ofInstant(instant, offset);
/** * Obtains the current date-time from the specified clock. * <p> * This will query the specified clock to obtain the current date-time. * The offset will be calculated from the time-zone in the clock. * <p> * Using this method allows the use of an alternate clock for testing. * The alternate clock may be introduced using {@link Clock dependency injection}. * * @param clock the clock to use, not null * @return the current date-time, not null */ public static OffsetDateTime now(Clock clock) { Jdk8Methods.requireNonNull(clock, "clock"); final Instant now = clock.instant(); // called once return ofInstant(now, clock.getZone().getRules().getOffset(now)); }
/** * Obtains the current date-time from the specified clock. * <p> * This will query the specified clock to obtain the current date-time. * The offset will be calculated from the time-zone in the clock. * <p> * Using this method allows the use of an alternate clock for testing. * The alternate clock may be introduced using {@link Clock dependency injection}. * * @param clock the clock to use, not null * @return the current date-time, not null */ public static OffsetDateTime now(Clock clock) { Jdk8Methods.requireNonNull(clock, "clock"); final Instant now = clock.instant(); // called once return ofInstant(now, clock.getZone().getRules().getOffset(now)); }
return with(dateTime.with(adjuster), offset); } else if (adjuster instanceof Instant) { return ofInstant((Instant) adjuster, offset); } else if (adjuster instanceof ZoneOffset) { return with(dateTime, (ZoneOffset) adjuster);
return with(dateTime.with(adjuster), offset); } else if (adjuster instanceof Instant) { return ofInstant((Instant) adjuster, offset); } else if (adjuster instanceof ZoneOffset) { return with(dateTime, (ZoneOffset) adjuster);
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)));
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)));