/** * Converts this date-time to an {@code OffsetDateTime}. * <p> * This creates an offset date-time using the local date-time and offset. * The zone ID is ignored. * * @return an offset date-time representing the same local date-time and offset, not null */ public OffsetDateTime toOffsetDateTime() { return OffsetDateTime.of(dateTime, offset); }
try { LocalDateTime ldt = LocalDateTime.from(temporal); return OffsetDateTime.of(ldt, offset); } catch (DateTimeException ignore) { Instant instant = Instant.from(temporal);
/** * Combines this time with a date to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this time and the specified date. * All possible combinations of date and time are valid. * * @param date the date to combine with, not null * @return the offset date-time formed from this time and the specified date, not null */ public OffsetDateTime atDate(LocalDate date) { return OffsetDateTime.of(date, time, offset); }
try { LocalDateTime ldt = LocalDateTime.from(temporal); return OffsetDateTime.of(ldt, offset); } catch (DateTimeException ignore) { Instant instant = Instant.from(temporal);
/** * Combines this date-time with an offset to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this date-time at the specified offset. * All possible combinations of date-time and offset are valid. * * @param offset the offset to combine with, not null * @return the offset date-time formed from this date-time and the specified offset, not null */ public OffsetDateTime atOffset(ZoneOffset offset) { return OffsetDateTime.of(this, offset); }
/** * Converts this date-time to an {@code OffsetDateTime}. * <p> * This creates an offset date-time using the local date-time and offset. * The zone ID is ignored. * * @return an offset date-time representing the same local date-time and offset, not null */ public OffsetDateTime toOffsetDateTime() { return OffsetDateTime.of(dateTime, offset); }
/** * Combines this date-time with an offset to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this date-time at the specified offset. * All possible combinations of date-time and offset are valid. * * @param offset the offset to combine with, not null * @return the offset date-time formed from this date-time and the specified offset, not null */ public OffsetDateTime atOffset(ZoneOffset offset) { return OffsetDateTime.of(this, offset); }
/** * Combines this time with a date to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this time and the specified date. * All possible combinations of date and time are valid. * * @param date the date to combine with, not null * @return the offset date-time formed from this time and the specified date, not null */ public OffsetDateTime atDate(LocalDate date) { return OffsetDateTime.of(date, time, offset); }
public static OffsetDateTime string2ODT(String timeStr) { if (!TextUtils.isEmpty(timeStr)) { DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); LocalDateTime localDateTime = LocalDateTime.parse(timeStr, df); return OffsetDateTime.of(localDateTime, ZoneOffset.UTC); } return null; } }
static OffsetDateTime readExternal(DataInput in) throws IOException { LocalDateTime dateTime = LocalDateTime.readExternal(in); ZoneOffset offset = ZoneOffset.readExternal(in); return OffsetDateTime.of(dateTime, offset); }
static OffsetDateTime readExternal(DataInput in) throws IOException { LocalDateTime dateTime = LocalDateTime.readExternal(in); ZoneOffset offset = ZoneOffset.readExternal(in); return OffsetDateTime.of(dateTime, offset); }
/** * Combines this date with an offset time to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this date at the specified time. * All possible combinations of date and time are valid. * * @param time the time to combine with, not null * @return the offset date-time formed from this date and the specified time, not null */ public OffsetDateTime atTime(OffsetTime time) { return OffsetDateTime.of(LocalDateTime.of(this, time.toLocalTime()), time.getOffset()); }
/** * Combines this date with an offset time to create an {@code OffsetDateTime}. * <p> * This returns an {@code OffsetDateTime} formed from this date at the specified time. * All possible combinations of date and time are valid. * * @param time the time to combine with, not null * @return the offset date-time formed from this date and the specified time, not null */ public OffsetDateTime atTime(OffsetTime time) { return OffsetDateTime.of(LocalDateTime.of(this, time.toLocalTime()), time.getOffset()); }
/** Returns TAI milliseconds mod 2^32 for the given date. * * Since java int is signed 32 bit integer, return long instead. * It is the same on byte level, but just to avoid confusing people with negative values here. * * * From http://stjarnhimlen.se/comp/time.html: * * TAI (Temps Atomique International or International Atomic Time) is * defined as the weighted average of the time kept by about 200 * atomic clocks in over 50 national laboratories worldwide. * TAI-UT1 was approximately 0 on 1958 Jan 1. * (TAI is ahead of UTC by 35 seconds as of 2014.) * * GPS time = TAI - 19 seconds. GPS time matched UTC from 1980-01-01 * to 1981-07-01. No leap seconds are inserted into GPS time, thus * GPS time is 13 seconds ahead of UTC on 2000-01-01. The GPS epoch * is 00:00 (midnight) UTC on 1980-01-06. * The difference between GPS Time and UTC changes in increments of * seconds each time a leap second is added to UTC time scale. */ public static long instantToTaiMillisSince2004Mod32(Instant instantX) { OffsetDateTime gnEpochStart = OffsetDateTime.of(LocalDateTime.of(2004, Month.JANUARY, 1, 0, 0), ZoneOffset.UTC); long millis2004 = gnEpochStart.toInstant().toEpochMilli(); long millisAtX = instantX.toEpochMilli(); long taiMillis = (millisAtX + LEAP_SECONDS_SINCE_2004*1000) - millis2004; return taiMillis % (1L << 32); }
if (tmp[19] == '.') { final int nanos = readNanos(tmp, len - 1); return OffsetDateTime.of(year, month, day, hour, min, sec, nanos, ZoneOffset.UTC); return OffsetDateTime.of(year, month, day, hour, min, sec, 0, ZoneOffset.UTC); } else if (len > 22 && len < 36 && tmp[len - 3] == ':' && (tmp[len - 6] == '+' || tmp[len - 6] == '-') if (tmp[19] == '.') { final int nanos = readNanos(tmp, len - 6); return OffsetDateTime.of(year, month, day, hour, min, sec, nanos, offset); return OffsetDateTime.of(year, month, day, hour, min, sec, 0, offset); } else { return OffsetDateTime.parse(new String(tmp, 0, len));
OffsetDateTime invModified = OffsetDateTime.of(LocalDateTime.of(2018, 12, 06, 15, 00), ZoneOffset.UTC);