The Calendar.setFirstDayOfWeek() method configures which weekday is considered the start of the week for week-number calculations.
Custom Week Boundaries: Modifies how WEEK_OF_YEAR and getWeeksInWeekYear() group calendar dates without altering the underlying timestamp. To inspect the current setting, see getFirstDayOfWeek(). To read field coordinates, see get().
Defined directly in java.util.Calendar:
// Formal signature of Calendar.setFirstDayOfWeek() in java.util.Calendar
public void setFirstDayOfWeek(int value)
| Parameter | Type | Description & Operational Rule |
|---|---|---|
value |
int |
The weekday constant to establish as the first day (Calendar.SUNDAY to Calendar.SATURDAY). |
| Return Type | void |
Updates the internal week-calculation state of the calendar instance in-place. |
| Timestamp Impact | None | Alters only week grouping; the underlying date, month, and time remain unchanged. |
Updating the starting weekday on an active calendar instance:
import java.util.Calendar;
Calendar cal = Calendar.getInstance();
// Default first day of week in US locale is Sunday (1)
System.out.println("Default First Day: " + cal.getFirstDayOfWeek()); // 1 (Sunday)
// Reconfigure first day to Monday (2)
cal.setFirstDayOfWeek(Calendar.MONDAY);
System.out.println("Updated First Day: " + cal.getFirstDayOfWeek()); // 2 (Monday)Terminal Output:
Default First Day: 1
Updated First Day: 2
Demonstrating how changing the first weekday shifts a calendar date into a different week number:
import java.util.Calendar;
Calendar cal = Calendar.getInstance();
cal.set(2026, Calendar.JANUARY, 4); // Sunday
// When Sunday starts the week: Jan 4 begins Week 2
cal.setFirstDayOfWeek(Calendar.SUNDAY);
System.out.println("Sunday Start Week: " + cal.get(Calendar.WEEK_OF_YEAR)); // 2
// When Monday starts the week: Sunday is the final day of Week 1
cal.setFirstDayOfWeek(Calendar.MONDAY);
System.out.println("Monday Start Week: " + cal.get(Calendar.WEEK_OF_YEAR)); // 1Terminal Output:
Sunday Start Week: 2
Monday Start Week: 1
Changing week boundaries can push boundary days into a 53rd week in getWeeksInWeekYear():
import java.util.Calendar;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2026);
// Sunday start produces 52 weeks in 2026
cal.setFirstDayOfWeek(Calendar.SUNDAY);
System.out.println("Weeks with Sunday Start: " + cal.getWeeksInWeekYear()); // 52
// Shifting to Thursday shifts borderline days, creating a 53rd week
cal.setFirstDayOfWeek(Calendar.THURSDAY);
System.out.println("Weeks with Thursday Start: " + cal.getWeeksInWeekYear()); // 53Terminal Output:
Weeks with Sunday Start: 52
Weeks with Thursday Start: 53
Standard integer constants passed to setFirstDayOfWeek():
| Constant | Integer Value | Standard Geographic / Business Context |
|---|---|---|
Calendar.SUNDAY |
1 |
Default in United States, Canada, and traditional retail calendars. |
Calendar.MONDAY |
2 |
ISO-8601 international business standard and European Union default. |
Calendar.SATURDAY |
7 |
Standard workweek start across Middle Eastern jurisdictions. |
Creating standardized calendars adhering strictly to the ISO-8601 specification:
import java.util.Calendar;
public class IsoCalendarFactory {
public static Calendar createIsoCalendar() {
Calendar cal = Calendar.getInstance();
// Configure standard ISO-8601 rules
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.setMinimalDaysInFirstWeek(4);
return cal;
}
public static void main(String[] args) {
Calendar iso = createIsoCalendar();
System.out.println("ISO First Day: " + iso.getFirstDayOfWeek()); // 2 (Monday)
}
}Terminal Output:
ISO First Day: 2
Configuring custom fiscal week numbering for corporate accounting schedules:
import java.util.Calendar;
public class RetailFiscalWeekHelper {
public static int getRetailWeek(Calendar date, int fiscalStartDay) {
Calendar cal = (Calendar) date.clone();
cal.setFirstDayOfWeek(fiscalStartDay);
return cal.get(Calendar.WEEK_OF_YEAR);
}
public static void main(String[] args) {
Calendar today = Calendar.getInstance();
today.set(2026, Calendar.JANUARY, 4);
int retailWeek = getRetailWeek(today, Calendar.SUNDAY);
System.out.println("Retail Fiscal Week: " + retailWeek); // 2
}
}Terminal Output:
Retail Fiscal Week: 2
In modern Java 8+, custom week definitions are modeled via immutable WeekFields:
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
// Modern Java 8+ WeekFields customization
WeekFields customWeeks = WeekFields.of(DayOfWeek.MONDAY, 4);
DayOfWeek startDay = customWeeks.getFirstDayOfWeek();
System.out.println("Modern Custom Week Start: " + startDay); // MONDAYTerminal Output:
Modern Custom Week Start: MONDAY
Valid parameters range strictly from 1 (Sunday) to 7 (Saturday). Always use named constants like Calendar.MONDAY rather than raw numbers.
Calling setFirstDayOfWeek(Calendar.MONDAY) is only half of ISO-8601. You must also invoke setMinimalDaysInFirstWeek(4) for true ISO compliance.
You can compile and run this complete verification class locally in any Java IDE or environment:
import java.util.Calendar;
public class CalendarSetFirstDayOfWeekFullDemo {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
// 1. Verify change to Saturday
cal.setFirstDayOfWeek(Calendar.SATURDAY);
if (cal.getFirstDayOfWeek() == Calendar.SATURDAY) {
System.out.println("Check 1 Passed: First day updated to Saturday.");
}
// 2. Verify change to Monday
cal.setFirstDayOfWeek(Calendar.MONDAY);
if (cal.getFirstDayOfWeek() == Calendar.MONDAY) {
System.out.println("Check 2 Passed: First day updated to Monday.");
}
// 3. Verify date integrity unchanged
cal.set(2026, Calendar.MAY, 15);
cal.setFirstDayOfWeek(Calendar.WEDNESDAY);
if (cal.get(Calendar.DATE) == 15) {
System.out.println("Check 3 Passed: Calendar date unchanged by week start change.");
}
System.out.println("All Calendar.setFirstDayOfWeek() verification checks passed!");
}
}Terminal Output:
Check 1 Passed: First day updated to Saturday.
Check 2 Passed: First day updated to Monday.
Check 3 Passed: Calendar date unchanged by week start change.
All Calendar.setFirstDayOfWeek() verification checks passed!
No. The underlying timestamp remains identical; only week groupings (e.g. WEEK_OF_YEAR) adapt.
Call cal.getFirstDayOfWeek(), which returns the integer constant.
Changing the first weekday shifts boundary days at the beginning or end of the year into a separate week.
Use WeekFields.of(startDay, minDays) from the java.time.temporal package.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.