Monday, 12 February 2018

How to use format method of OffsetDateTime Class | Java 8 Date and Time


Click here to watch on Youtube : 
https://www.youtube.com/watch?v=TVTPeoMLrn0&list=UUhwKlOVR041tngjerWxVccw

OffsetDateTimeDemo.java

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

public class OffsetDateTimeDemo
{

    public static void main(String[] args)
    {

        OffsetDateTime offsetDateTime = OffsetDateTime.now();
        System.out.println(offsetDateTime);
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_DATE;

        /*
         * Parameters:
         *
         * formatter - the formatter to use, not null
         *
         * Returns:
         *
         * the formatted date-time string, not null
         */

        String formatedDate = offsetDateTime.format(dateTimeFormatter);
        System.out.println("ISO_DATE = " + formatedDate);

        dateTimeFormatter = DateTimeFormatter.ISO_TIME;
        formatedDate = offsetDateTime.format(dateTimeFormatter);
        System.out.println("ISO_TIME = " + formatedDate);

    }

}

Output

2018-01-27T09:00:14.857+05:30
ISO_DATE = 2018-01-27+05:30
ISO_TIME = 09:00:14.857+05:30

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/572947048c5892379e75d8e421fa231c20e2d3bc/BasicJava/OffsetDateTimeDemo_format/?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