.setFirstDayOfWeek()
Anonymous contributor
Published Oct 27, 2023
Contribute to Docs
The .setFirstDayOfWeek()
method of the Calendar
class sets what the first day of all weeks will be by accepting an integer value that represents a specific day of the week.
Note: Most countries consider either Saturday, Sunday, or Monday to be the first day of the week. For example, the United States recognizes Sunday as the first day of the week, while Monday is observed as the first day of the week in India.
Syntax
calendar.setFirstDayOfWeek(day_val)
This method takes only one argument, day_val
, which is an integer that represents one of seven days of the week (e.g. Calendar.FRIDAY
). It does not return a value.
Example
In the example below, the .setFirstDayOfWeek()
method is used to change the first day of the week.
import java.util.Calendar;public class FirstDayOfWeek {public static void main(String[] args) {// Creates a calendar object.Calendar cal = Calendar.getInstance();// Retrieves and prints the current first day of the week.int firstDay = cal.getFirstDayOfWeek();System.out.println("First day of the week: " + firstDay);// Changes the first day of the week.cal.setFirstDayOfWeek(Calendar.SATURDAY);int newFirstDay = cal.getFirstDayOfWeek();System.out.println("New first day of the week: " + newFirstDay);}}
This code returns the following output:
First day of the week: 1New first day of the week: 7
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Java on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly16 hours