LocalDate getDayOfWeek() example
Description
LocalDate getDayOfWeek()
gets the day-of-week field, which is an enum DayOfWeek.
This method returns the enum DayOfWeek for the day-of-week.
Syntax
getDayOfWeek
has the following syntax.
public DayOfWeek getDayOfWeek()
Example
The following example shows how to use getDayOfWeek
.
import java.time.LocalDate;
/*ww w.ja va2 s . c o m*/
public class Main {
public static void main(String[] args) {
LocalDate a = LocalDate.of(2014, 6, 30);
System.out.println(a.getDayOfWeek().name());
}
}
The code above generates the following result.
Example 2
Get day of week for a given LocalDate
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
/*from www .j a v a 2s .c o m*/
public class Main {
public static void main(String... args) {
LocalDate independenceDay = LocalDate.of(2014, Month.JULY, 4);
DayOfWeek dayOfWeek = independenceDay.getDayOfWeek();
System.out.println(dayOfWeek); // FRIDAY
}
}
The code above generates the following result.