Monday 12 February 2018

How to convert string date to OffsetDateTime using parse method of OffsetDateTime Class


Click here to watch on Youtube :
https://www.youtube.com/watch?v=014vE1N-WxM&list=UUhwKlOVR041tngjerWxVccw

OffsetDateTimeDemo.java

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;

public class OffsetDateTimeDemo
{

    public static void main(String[] args)
    {

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
        String strDate = "2017-12-03T10:15:30+01:00";

        /*
         * Parameters:
         *
         * text - the text to parse, not null
         *
         * formatter - the formatter to use, not null
         *
         * Returns:
         *
         * the parsed offset date-time, not null
         */

        OffsetDateTime offsetDateTime = OffsetDateTime.parse(strDate,
                dateTimeFormatter);
        System.out.println(offsetDateTime);
    }

}

Output

2017-12-03T10:15:30+01:00

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/OffsetDateTimeDemo_parse_formatter.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/OffsetDateTimeDemo_parse_formatter

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/572947048c5892379e75d8e421fa231c20e2d3bc/BasicJava/OffsetDateTimeDemo_parse_formatter/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment