Friday, 8 June 2018

How to use get methods of DayOfWeek Enum | Java 8 Date and Time


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

DayOfWeekDemo1.java

import java.time.DayOfWeek;
import java.time.temporal.ChronoField;

public class DayOfWeekDemo1
{
    public static void main(String[] args)
    {
        DayOfWeek dayOfWeek = DayOfWeek.TUESDAY;
        System.out.println("dayOfWeek = "+dayOfWeek);
       
        /*
         * Parameters:
         *
         * field - the field to get, not null
         *
         * Returns:
         *
         * the value for the field
         */

        long value = dayOfWeek.getLong(ChronoField.DAY_OF_WEEK);       
        System.out.println(value);
    }

}

Output

dayOfWeek = TUESDAY
2

DayOfWeekDemo2.java

import java.time.DayOfWeek;
import java.time.temporal.ChronoField;

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

         DayOfWeek dayOfWeek = DayOfWeek.SUNDAY;
         System.out.println("dayOfWeek = "+dayOfWeek);

        /*
         * Parameters:
         *
         * field - the field to get, not null
         *
         * Returns:
         *
         * the value for the field, within the valid range of values
         */

        int value = dayOfWeek.get(ChronoField.DAY_OF_WEEK);
        System.out.println(value);

    }

}

Output

dayOfWeek = SUNDAY
7

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/23d89f367bac9ed4230eafe0abaf49c0a80cc445/BasicJava_2018/DayOfWeekDemo_get/?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