
OffsetTime toOffsetTime(): Converts this date-time to an OffsetTime.LocalTime toLocalTime(): Gets the LocalTime part of this date-time.LocalDateTime toLocalDateTime(): Gets the LocalDateTime part of this date-time.LocalDate toLocalDate(): Gets the LocalDate part of this date-time.
Instant toInstant(): Converts this date-time to an Instant.long toEpochSecond(): Converts this date-time to the number of seconds from the epoch of.int getSecond(): Gets the second-of-minute field.Īnd following methods can be used to get another class (or convert) from an OffsetDateTime instance:.
ZoneOffset getOffset(): Gets the zone offset, such as '+01:00'. int getNano(): Gets the nano-of-second field. int getMonthValue(): Gets the month-of-year field from 1 to 12. Month getMonth(): Gets the month-of-year field using the Month enum. int getMinute(): Gets the minute-of-hour field. long getLong(TemporalField field): Gets the value of the specified field from this date-time as a long. int getHour(): Gets the hour-of-day field. int getDayOfYear(): Gets the day-of-year field. DayOfWeek getDayOfWeek(): Gets the day-of-week field, which is an enum DayOfWeek. int getDayOfMonth(): Gets the day-of-month field. int get(TemporalField field): Gets the value of the specified field from this date-time as an int. OffsetDateTime9: T08:20:45+07:00 Getting Information from an OffsetDateTimeįollowing methods can be used to access Date and/or Time information from an OffsetDateTime: OffsetDateTime offsetDT9 = OffsetDateTime.parse("T08:20:45+07:00", DateTimeFormatter.ISO_OFFSET_DATE_TIME) OffsetDateTime offsetDT8 = OffsetDateTime.parse("T15:20:30+08:00") OffsetDateTime offsetDT7 = OffsetDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()) OffsetDateTime offsetDT6 = OffsetDateTime.of(LocalDateTime.now(), ZoneOffset.of("+07:00")) OffsetDateTime offsetDT5 = OffsetDateTime.of(LocalDate.now(), LocalTime.of(15, 50, 25), ZoneOffset.of("+07:00")) OffsetDateTime offsetDT3 = OffsetDateTime.now(ZoneId.of("Asia/Jakarta")) OffsetDateTime offsetDT2 = OffsetDateTime.now(Clock.systemUTC()) OffsetDateTime offsetDT1 = OffsetDateTime.now() You can create a ZoneOffset object using the ZoneId.of(.) method. The time zone offsets are represented by the ZoneOffset class. static OffsetDateTime parse(CharSequence text, DateTimeFormatter formatter): Obtains an instance of OffsetDateTime from a text string using a specific formatter. static OffsetDateTime parse(CharSequence text): Obtains an instance of OffsetDateTime from a text string such as T15:20:30+08:00. static OffsetDateTime ofInstant(Instant instant, ZoneId zone): Obtains an instance of OffsetDateTime from an Instant and zone ID. static OffsetDateTime of(LocalDateTime dateTime, ZoneOffset offset): Obtains an instance of OffsetDateTime from a date-time and offset. static OffsetDateTime of(LocalDate date, LocalTime time, ZoneOffset offset): Obtains an instance of OffsetDateTime from a date, time and offset. static OffsetDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset): Obtains an instance of OffsetDateTime from a year, month, day, hour, minute, second, nanosecond and offset. static OffsetDateTime now(ZoneId zone): Obtains the current date-time from the system clock in the specified time-zone. static OffsetDateTime now(Clock clock): Obtains the current date-time from the specified clock. static OffsetDateTime now(): Obtains the current date-time from the system clock in the default time-zone. We can create an OffsetDateTime in several ways: