/** * Combines this time with a date to create a {@code LocalDateTime}. * <p> * This returns a {@code LocalDateTime} formed from this time at the specified date. * All possible combinations of date and time are valid. * * @param date the date to combine with, not null * @return the local date-time formed from this time and the specified date, not null */ public LocalDateTime atDate(LocalDate date) { return LocalDateTime.of(date, this); }
/** * Combines this date with the time of midnight to create a {@code LocalDateTime} * at the start of this date. * <p> * This returns a {@code LocalDateTime} formed from this date at the time of * midnight, 00:00, at the start of this date. * * @return the local date-time of midnight at the start of this date, not null */ public LocalDateTime atStartOfDay() { return LocalDateTime.of(this, LocalTime.MIDNIGHT); }
/** * Combines this time with a date to create a {@code LocalDateTime}. * <p> * This returns a {@code LocalDateTime} formed from this time at the specified date. * All possible combinations of date and time are valid. * * @param date the date to combine with, not null * @return the local date-time formed from this time and the specified date, not null */ public LocalDateTime atDate(LocalDate date) { return LocalDateTime.of(date, this); }
/** * Combines this date with the time of midnight to create a {@code LocalDateTime} * at the start of this date. * <p> * This returns a {@code LocalDateTime} formed from this date at the time of * midnight, 00:00, at the start of this date. * * @return the local date-time of midnight at the start of this date, not null */ public LocalDateTime atStartOfDay() { return LocalDateTime.of(this, LocalTime.MIDNIGHT); }
/** * Combines this date with a time to create a {@code LocalDateTime}. * <p> * This returns a {@code LocalDateTime} 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 local date-time formed from this date and the specified time, not null */ @Override public LocalDateTime atTime(LocalTime time) { return LocalDateTime.of(this, time); }
/** * Combines this date with a time to create a {@code LocalDateTime}. * <p> * This returns a {@code LocalDateTime} 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 local date-time formed from this date and the specified time, not null */ @Override public LocalDateTime atTime(LocalTime time) { return LocalDateTime.of(this, time); }
/** * Obtains an instance of {@code OffsetDateTime} from a date, time and offset. * <p> * This creates an offset date-time with the specified local date, time and offset. * * @param date the local date, not null * @param time the local time, not null * @param offset the zone offset, not null * @return the offset date-time, not null */ public static OffsetDateTime of(LocalDate date, LocalTime time, ZoneOffset offset) { LocalDateTime dt = LocalDateTime.of(date, time); return new OffsetDateTime(dt, offset); }
/** * Obtains an instance of {@code OffsetDateTime} from a date, time and offset. * <p> * This creates an offset date-time with the specified local date, time and offset. * * @param date the local date, not null * @param time the local time, not null * @param offset the zone offset, not null * @return the offset date-time, not null */ public static OffsetDateTime of(LocalDate date, LocalTime time, ZoneOffset offset) { LocalDateTime dt = LocalDateTime.of(date, time); return new OffsetDateTime(dt, offset); }
static LocalDateTime readExternal(DataInput in) throws IOException { LocalDate date = LocalDate.readExternal(in); LocalTime time = LocalTime.readExternal(in); return LocalDateTime.of(date, time); }
static LocalDateTime readExternal(DataInput in) throws IOException { LocalDate date = LocalDate.readExternal(in); LocalTime time = LocalTime.readExternal(in); return LocalDateTime.of(date, time); }
/** * 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()); }
@Before public void setUp() throws Exception { jsr301DateTime = LocalDateTime.of(1970, Month.MAY, 18, 13, 30, 0, 20000000); jsr301Date = LocalDate.of(1970, Month.MAY, 18); jsr301Time = LocalTime.of(13, 30, 0); jodaDateTime = new DateTime(1970, 5, 18, 13, 30, 0, 20); jodaDateTimeUtc = new DateTime(1970, 5, 18, 13, 30, 0, 20, DateTimeZone.UTC); }
/** * Converts a {@code java.sql.Timestamp} to a {@code LocalDateTime}. * * @param sqlTimestamp the SQL timestamp, not null * @return the local date-time, not null */ @SuppressWarnings("deprecation") public static LocalDateTime toLocalDateTime(Timestamp sqlTimestamp) { return LocalDateTime.of( sqlTimestamp.getYear() + 1900, sqlTimestamp.getMonth() + 1, sqlTimestamp.getDate(), sqlTimestamp.getHours(), sqlTimestamp.getMinutes(), sqlTimestamp.getSeconds(), sqlTimestamp.getNanos()); }
/** * Converts a {@code java.sql.Timestamp} to a {@code LocalDateTime}. * * @param sqlTimestamp the SQL timestamp, not null * @return the local date-time, not null */ @SuppressWarnings("deprecation") public static LocalDateTime toLocalDateTime(Timestamp sqlTimestamp) { return LocalDateTime.of( sqlTimestamp.getYear() + 1900, sqlTimestamp.getMonth() + 1, sqlTimestamp.getDate(), sqlTimestamp.getHours(), sqlTimestamp.getMinutes(), sqlTimestamp.getSeconds(), sqlTimestamp.getNanos()); }
public static LocalDateTime deserializeLocalDateTime(final JsonReader reader) throws IOException { final char[] tmp = reader.readSimpleQuote(); final int len = reader.getCurrentIndex() - reader.getTokenStart() - 1; if (len > 18 && len < 30 && tmp[4] == '-' && tmp[7] == '-' && (tmp[10] == 'T' || tmp[10] == 't' || tmp[10] == ' ') && tmp[13] == ':' && tmp[16] == ':' && allDigits(tmp, 20, len)) { final int year = NumberConverter.read4(tmp, 0); final int month = NumberConverter.read2(tmp, 5); final int day = NumberConverter.read2(tmp, 8); final int hour = NumberConverter.read2(tmp, 11); final int min = NumberConverter.read2(tmp, 14); final int sec = NumberConverter.read2(tmp, 17); if (len > 19 && tmp[19] == '.') { final int nanos = readNanos(tmp, len); return LocalDateTime.of(year, month, day, hour, min, sec, nanos); } return LocalDateTime.of(year, month, day, hour, min, sec); } else { return LocalDateTime.parse(new String(tmp, 0, len)); } }
private LocalDateTime toDateTime(int year) { adjustToFowards(year); LocalDate date; if (dayOfMonth == -1) { dayOfMonth = month.length(Year.isLeap(year)); date = LocalDate.of(year, month, dayOfMonth); if (dayOfWeek != null) { date = date.with(TemporalAdjusters.previousOrSame(dayOfWeek)); } } else { date = LocalDate.of(year, month, dayOfMonth); if (dayOfWeek != null) { date = date.with(TemporalAdjusters.nextOrSame(dayOfWeek)); } } date = deduplicate(date.plusDays(adjustDays)); return LocalDateTime.of(date, time); } }
private LocalDateTime toDateTime(int year) { adjustToFowards(year); LocalDate date; if (dayOfMonth == -1) { dayOfMonth = month.length(Year.isLeap(year)); date = LocalDate.of(year, month, dayOfMonth); if (dayOfWeek != null) { date = date.with(TemporalAdjusters.previousOrSame(dayOfWeek)); } } else { date = LocalDate.of(year, month, dayOfMonth); if (dayOfWeek != null) { date = date.with(TemporalAdjusters.nextOrSame(dayOfWeek)); } } date = deduplicate(date.plusDays(adjustDays)); return LocalDateTime.of(date, time); } }
/** * Converts this to a transition. * * @param standardOffset the active standard offset, not null * @param savingsBeforeSecs the active savings in seconds * @return the transition, not null */ ZoneOffsetTransition toTransition(ZoneOffset standardOffset, int savingsBeforeSecs) { // copy of code in ZoneOffsetTransitionRule to avoid infinite loop LocalDate date = toLocalDate(); date = deduplicate(date); LocalDateTime ldt = deduplicate(LocalDateTime.of(date.plusDays(adjustDays), time)); ZoneOffset wallOffset = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsBeforeSecs)); LocalDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset)); ZoneOffset offsetAfter = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingAmountSecs)); return new ZoneOffsetTransition(dt, wallOffset, offsetAfter); }
/** * Converts this to a transition. * * @param standardOffset the active standard offset, not null * @param savingsBeforeSecs the active savings in seconds * @return the transition, not null */ ZoneOffsetTransition toTransition(ZoneOffset standardOffset, int savingsBeforeSecs) { // copy of code in ZoneOffsetTransitionRule to avoid infinite loop LocalDate date = toLocalDate(); date = deduplicate(date); LocalDateTime ldt = deduplicate(LocalDateTime.of(date.plusDays(adjustDays), time)); ZoneOffset wallOffset = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingsBeforeSecs)); LocalDateTime dt = deduplicate(timeDefinition.createDateTime(ldt, standardOffset, wallOffset)); ZoneOffset offsetAfter = deduplicate(ZoneOffset.ofTotalSeconds(standardOffset.getTotalSeconds() + savingAmountSecs)); return new ZoneOffsetTransition(dt, wallOffset, offsetAfter); }