Monday 15 January 2018

How to format the date using DateTimeFormatter | Java 8 LocalDate Class | Java 8 Date and Time


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

LocalDateDemo.java

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class LocalDateDemo
{

    public static void main(String[] args)
    {
        LocalDate localDate = LocalDate.parse("2020-12-23");
        System.out.println(localDate);

        /*
         * Parameters:
         *
         * pattern - the pattern to use, not null
         *
         * Returns:
         *
         * the formatter based on the pattern, not null
         */

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter
                .ofPattern("dd/MM/YYYY");

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


        String formatedDate = localDate.format(dateTimeFormatter);
        System.out.println(formatedDate);
    }

}

Output

2020-12-23
23/12/2020

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/f50b0477cba623e7ace08d1d7966409dcc9e7b40/BasicJava/LocalDateDemo_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