Wednesday, July 3, 2024
HomeLanguagesJavaWeekFields getFirstDayOfWeek() method in Java with Examples

WeekFields getFirstDayOfWeek() method in Java with Examples

The getFirstDayOfWeek() method of WeekFields class is used to return the first day-of-week as a DayOfWeek enum.For example, the US uses Sunday, while France uses Monday.

Syntax:

public DayOfWeek getFirstDayOfWeek()

Parameters: This method accepts nothing.

Return value: This method returns the first day-of-week, not null.

Below programs illustrate the WeekFields.getFirstDayOfWeek() method:
Program 1:




// Java program to demonstrate
// WeekFields.getFirstDayOfWeek() method
  
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create WeekFields
        WeekFields weekFields
            = WeekFields.of(DayOfWeek.MONDAY, 1);
  
        // apply getFirstDayOfWeek()
        DayOfWeek firstDay
            = weekFields.getFirstDayOfWeek();
  
        // print results
        System.out.println("First Day:"
                           + firstDay);
    }
}


Output:

First Day:MONDAY

Program 2:




// Java program to demonstrate
// WeekFields.getFirstDayOfWeek() method
  
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
import java.util.Locale;
  
public class GFG {
    public static void main(String[] args)
    {
  
        Locale locale = new Locale("EN", "US");
  
        // create WeekFields
        WeekFields weekFields
            = WeekFields.of(locale);
  
        // apply getFirstDayOfWeek()
        DayOfWeek firstDay
            = weekFields.getFirstDayOfWeek();
  
        // print results
        System.out.println("First Day:"
                           + firstDay);
    }
}


Output:

First Day:SUNDAY

References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#getFirstDayOfWeek()

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments