Java Date Time - OffsetDateTime parse(CharSequence text, DateTimeFormatter formatter) example








OffsetDateTime parse(CharSequence text, DateTimeFormatter formatter) creates an instance of OffsetDateTime from a text string using a specific formatter.

Syntax

parse has the following syntax.

public static OffsetDateTime parse(CharSequence text,    DateTimeFormatter formatter)

Example

The following example shows how to use parse.

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
//from   w  w  w .  j ava2 s .  c o m
public class Main {
  public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.parse("2014-09-02T15:22:14.59-07:00",DateTimeFormatter.ISO_DATE_TIME);
    
    System.out.println(o);
  }
}

The code above generates the following result.