Close

Java Date Time - DayOfWeek.getValue() Examples

Java Date Time Java Java API 


Class:

java.time.DayOfWeek

java.lang.Objectjava.lang.Objectjava.lang.Enumjava.lang.Enumjava.lang.ComparableComparablejava.io.SerializableSerializablejava.time.DayOfWeekjava.time.DayOfWeekjava.time.temporal.TemporalAccessorTemporalAccessorjava.time.temporal.TemporalAdjusterTemporalAdjusterLogicBig

Method:

public int getValue()

The method DayOfWeek.getValue() returns the int value of the number of day from the start of week. Week numbers follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).


Examples


Finding day value on Dec 15, 1995.

package com.logicbig.example.dayofweek;

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

public class GetValueExample {
public static void main (String[] args) {
int value = LocalDate.of(1995, Month.DECEMBER, 15)
.getDayOfWeek()
.getValue();
System.out.println(value);
}
}

Output

5




This example finds out what will be the day on the same date after one year.

package com.logicbig.example.dayofweek;

import java.time.DayOfWeek;
import java.time.LocalDate;

public class GetValueExample2 {
public static void main (String[] args) {
DayOfWeek day = LocalDate.now()
.plusYears(1)
.getDayOfWeek();

System.out.println(day);
System.out.println(day.getValue());
}
}

Output

TUESDAY
2




See Also