Friday 1 June 2018

Java 8 Month Enum Introduction | Java 8 Date and Time | Java Date and Time


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

Click the below Image to Enlarge:
Java 8 Month Enum Introduction | Java 8 Date and Time | Java Date and Time

Java 8 Month Enum Introduction | Java 8 Date and Time | Java Date and Time

MonthDemo1.java

import java.time.Month;

public class MonthDemo1
{
    public static void main(String[] args)
    {
        Month month = Month.JULY;

        /*
         * Returns the name of this enum constant
         */

        System.out.println("Name = " + month.name());
        /*
         * Gets the month-of-year int value.
         */

        System.out.println("Value = " + month.getValue());
    }

}

Output

Name = JULY
Value = 7

MonthDemo2.java

import java.time.LocalDate;
import java.time.Month;

public class MonthDemo2
{
    public static void main(String[] args)
    {

        LocalDate localDate = LocalDate.now();
        System.out.println("localDate = " + localDate);

        /*
         * Obtains an instance of Month from a temporal object.
         *
         * Parameters:
         *
         * temporal - the temporal object to convert, not null
         *
         * Returns:
         *
         * the month-of-year, not null
         */

        Month month = Month.from(localDate);
        System.out.println("Name = " + month.name());
        System.out.println("Value = " + month.getValue());
    }

}

Output

localDate = 2018-04-10
Name = APRIL
Value = 4

Refer: 
https://docs.oracle.com/javase/8/docs/api/index.html?java/time/Month.html

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/80c7c27095bd0aa4eb0109eac12d92549dcd717d/BasicJava_2018/MonthDemo_intro/?at=master

See also:

  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Spring Tutorial
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a Comment