Wednesday, 21 March 2018

How to create a YearMonth object using parse methods of YearMonth Class


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

YearMonthDemo1.java

import java.time.YearMonth;

public class YearMonthDemo1
{

    public static void main(String[] args)
    {

        /*
         * Parameters:
         *
         * text - the text to parse such as "2007-12", not null
         *
         * Returns:
         *
         * the parsed year-month, not null
         */

        YearMonth yearMonth = YearMonth.parse("2017-03");
        System.out.println(yearMonth);

    }

}

Output

2017-03

YearMonthDemo2.java

import java.time.YearMonth;
import java.time.format.DateTimeFormatter;

public class YearMonthDemo2
{

    public static void main(String[] args)
    {

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter
                .ofPattern("yyyy-MM");
        /*
         * Parameters:
         *
         * text - the text to parse, not null formatter - the
         * formatter to use, not null
         *
         * Returns:
         *
         * the parsed year-month, not null
         */

        YearMonth yearMonth = YearMonth.parse("2017-09", dateTimeFormatter);
        System.out.println(yearMonth);
    }

}

Output

2017-09

Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/YearMonthDemo_parse_methods.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/YearMonthDemo_parse_methods

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/216f8f4e86e1a06aad30bc4ca526053adcad4b65/BasicJava_2018/YearMonthDemo_parse_methods/?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
  • Cooking Tutorial
  • No comments:

    Post a Comment