LAST UPDATED: JUNE 15, 2020
Java LocalDate getDayOfWeek() Method
This method is used to get day of week of a date. For example, we have a date and want to get day of week like: Sunday, Monday etc, then we can use this method.
It does not take any argument and returns full name of day of the specified date. Syntax of the method is given below.
Syntax
public DayOfWeek getDayOfWeek()
Parameters:
It does not take any parameter.
Returns:
It returns day of week that shows full name of the week.
Time for an Example:
Lets take an example to get day of week of a date by using the getDayOfWeek()
method. It is helpful when we want to get full day name from a date.
import java.time.DayOfWeek;
import java.time.LocalDate;
public class DateDemo {
public static void main(String[] args){
LocalDate localDate = LocalDate.of(2018, 2, 20);
System.out.println(localDate);
DayOfWeek dayOfWeek = localDate.getDayOfWeek();
System.out.println("day of week : "+dayOfWeek);
}
}
2018-02-20
day of week : TUESDAY
Time for another Example:
Lets take another example where we are getting day of week of a date that represents a long time in the future. We are getting day of year 2050 which is not easy to get without this method.
import java.time.DayOfWeek;
import java.time.LocalDate;
public class DateDemo {
public static void main(String[] args){
LocalDate localDate = LocalDate.of(2050, 2, 25);
System.out.println(localDate);
DayOfWeek dayOfWeek = localDate.getDayOfWeek();
System.out.println("day of week : "+dayOfWeek);
}
}
2050-02-25
day of week : FRIDAY
Live Example:
Try with a live example, execute the code instantly with our powerful Online Java Compiler.