Wednesday 31 January 2018

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


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

MonthDayDemo.java

import java.time.MonthDay;
import java.time.format.DateTimeFormatter;

public class MonthDayDemo
{

    public static void main(String[] args)
    {
        MonthDay monthDay = MonthDay.parse("--12-30");
        System.out.println(monthDay);

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

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("--MM");

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


        String formatedValue = monthDay.format(formatter);
        System.out.println(formatedValue);
    }

}

Output

--12-30
--12

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

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

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