As compare to
LocalDateTime.parse(..),
these parse methods need the offset
string part (+/-hh:mm) at the end. For example 2007-12-03T10:15:30+01:00
public static OffsetDateTime parse(CharSequence text)
This method internally calls other overloaded method:
parse(text, DateTimeFormatter.ISO_OFFSET_DATE_TIME).
The constant
DateTimeFormatter.ISO_OFFSET_DATE_TIME, formats or parses a date-time with an offset
public static OffsetDateTime parse(CharSequence text,
DateTimeFormatter formatter)
With this overloaded static method, we can specify our own formatter, or we can use one of the supported pre-defined
constants of DateTimeFormatter class which support date-time with an offset id.
Examples
package com.logicbig.example.offsetdatetime;
import java.time.OffsetDateTime;
public class ParseExample {
public static void main(String... args) {
OffsetDateTime date = OffsetDateTime.parse("2016-10-26T12:00-06:00"); System.out.println(date);