OffsetDateTime parse(CharSequence text, DateTimeFormatter formatter) example

Description

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;
//  w  ww  .j av a  2  s.co  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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset