The getDayOfWeek() method of an LocalDateTime class is used to return the day-of-week field, which is an enum DayOfWeek. This method returns the enum DayOfWeek for the day-of-week.
Syntax:
public DayOfWeek getDayOfWeek()
Parameter: This method do not accepts any parameter.
Returns: This method returns the day-of-week from the enum DayOfWeek.
Below programs illustrate the LocalDateTime.getDayOfWeek() method:
Program 1:
// Java program to demonstrate // LocalDateTime.getDayOfWeek() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalDateTime Object LocalDateTime local = LocalDateTime.parse("2018-12-03T12:39:10"); // get dayofweek for this LocalDateTime DayOfWeek dayofweek = local.getDayOfWeek(); // print result System.out.println("Day of Week: " + dayofweek); } } |
Day of Week: MONDAY
Program 2:
// Java program to demonstrate // LocalDateTime.getDayOfWeek() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalDateTime Object LocalDateTime local = LocalDateTime.parse("2018-12-29T02:39:10"); // get dayofweek for this LocalDateTime DayOfWeek dayofweek = local.getDayOfWeek(); // print result System.out.println("Day of Week: " + dayofweek); } } |
Day of Week: SATURDAY
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDateTime.html#getDayOfWeek()
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- ZonedDateTime getDayOfWeek() method in Java with Examples
- OffsetDateTime getDayOfWeek() method in Java with examples
- LocalDate getDayOfWeek() method in Java
- ZoneOffsetTransitionRule getDayOfWeek() method in Java with Example
- LocalDateTime isAfter() method in Java with Examples
- LocalDateTime equals() method in Java with Examples
- LocalDateTime getDayOfMonth() method in Java with Examples
- LocalDateTime getDayOfYear() method in Java with Examples
- LocalDateTime getHour() method in Java with Examples
- LocalDateTime getYear() method in Java with Examples
- LocalDateTime getSecond() method in Java with Examples
- LocalDateTime getMinute() method in Java with Examples
- LocalDateTime getNano() method in Java with Examples
- LocalDateTime hashCode() method in Java with Examples
- LocalDateTime getMonth() method in Java with Examples
- LocalDateTime getMonthValue() method in Java with Examples
- LocalDateTime compareTo() method in Java with Examples
- LocalDateTime isEqual() method in Java with Examples
- LocalDateTime plusMinutes() method in Java with Examples
- LocalDateTime plusHours() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

