Tuesday 30 January 2018

How to use format method which accepts DateTimeFormatter | LocalDateTime Class


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

LocalDateTimeDemo.java

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class LocalDateTimeDemo
{

    public static void main(String[] args)
    {
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println("Before Formatting = " + localDateTime);

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


        DateTimeFormatter dateTimeFormatter = DateTimeFormatter
                .ofPattern("dd-MM-yyyy HH:mm:ss");

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

        String formatDateTime = localDateTime.format(dateTimeFormatter);
        System.out.println("After Formatting  = " + formatDateTime);
    }

}

Output

Before Formatting = 2018-01-17T10:09:54.188
After Formatting  = 17-01-2018 10:09:54

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8fa516d67356209c67bf6743dfb7e718c4c9e5f6/BasicJava/LocalDateTimeDemo_format_datetimeformatter/?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