Saturday, September 6, 2025
HomeLanguagesJavaDayOfWeek getValue() method in Java with Examples

DayOfWeek getValue() method in Java with Examples

The getValue() method of java.time.DayOfWeek is an in-built function in Java which return the integer value assigned to the 7 days of the week, i.e, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The int value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).

Method Declaration:

public int getValue()

Syntax:

int val = DayOfWeekObject.getValue()

Parameters: This method does not accepts any parameters.

Return Value: The function returns int value of the day of the week, e.g, 1 for Monday, 2 for Tuesday and so on.

Below program illustrate the above method:
Program 1:




// Java Program Demonstrate getValue()
// method of DayOfWeek
import java.time.*;
import java.time.DayOfWeek;
  
class DayOfWeekExample {
    public static void main(String[] args)
    {
        // Set a local date whose day is found
        LocalDate localDate
            = LocalDate.of(1947,
                           Month.AUGUST, 15);
  
        // Find the day from the local date
        DayOfWeek dayOfWeek
            = DayOfWeek.from(localDate);
  
        // Printing the day of the week
        // and its Int value
        System.out.println("Day of the Week on"
                           + " 15th August 1947 - "
                           + dayOfWeek.name());
  
        int val = dayOfWeek.getValue();
  
        System.out.println("Int Value of "
                           + dayOfWeek.name()
                           + " - " + val);
    }
}


Output:

Day of the Week on 15th August 1947 - FRIDAY
Int Value of FRIDAY - 5

Program 2:




// Java Program Demonstrate getValue()
// method of DayOfWeek
import java.time.*;
import java.time.DayOfWeek;
  
class DayOfWeekExample {
    public static void main(String[] args)
    {
        // Set a local date whose day is found
        LocalDate localDate
            = LocalDate.of(2015,
                           Month.JULY, 13);
  
        // Find the day from the local date
        DayOfWeek dayOfWeek
            = DayOfWeek.from(localDate);
  
        // Printing the day of the week
        // and its Int value
        System.out.println("Day of the Week on"
                           + " 13th July 2015 - "
                           + dayOfWeek.name());
  
        int val = dayOfWeek.getValue();
  
        System.out.println("Int Value of "
                           + dayOfWeek.name()
                           + " - " + val);
    }
}


Output:

Day of the Week on 13th July 2015 - MONDAY
Int Value of MONDAY - 1

Reference: https://docs.oracle.com/javase/8/docs/api/java/time/DayOfWeek.html#getValue–

RELATED ARTICLES

Most Popular

Dominic
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS