Monday, 5 February 2018

How to convert String date to MonthDay using parse method of MonthDay Class



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

MonthDayDemo.java

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

public class MonthDayDemo
{

    public static void main(String[] args)
    {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter
                .ofPattern("--MM-dd");
        String strDate = "--11-15";

        /*
         * Parameters:
         *
         * text - the text to parse, not null
         *
         * formatter - the formatter to use, not nullReturns:the
         * parsed month-day, not null
         *
         * Returns:
         *
         * the parsed month-day, not null
         *
         */

        MonthDay monthDay = MonthDay.parse(strDate, dateTimeFormatter);
        System.out.println(monthDay);
    }

}

Output

--11-15

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

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

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