Skip to content
Related Articles

Related Articles

LocalDateTime getDayOfWeek() method in Java with Examples

View Discussion
Improve Article
Save Article
  • Last Updated : 29 Nov, 2018
View Discussion
Improve Article
Save Article

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);
    }
}

Output:

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);
    }
}

Output:

Day of Week: SATURDAY

Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDateTime.html#getDayOfWeek()


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!