Calendar setFirstDayOfWeek() Method in Java with Examples
Last Updated :
21 Feb, 2019
The setFirstDayOfWeek(int day_val) method in Calendar class is used to set the first day of the week using the day_val in this Calendar.
Syntax:
public void set(int day_val)
Parameters: The method takes one parameter day_val of integer type and refers to the first day of the week.
Return Value: The method does not return any value.
Below programs illustrate the working of setFirstDayOfWeek() Method of Calendar class:
Example 1:
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
{
Calendar calndr = Calendar.getInstance();
int first_day = calndr.getFirstDayOfWeek();
System.out.println( "The Current"
+ " First day of the week: "
+ first_day);
calndr.setFirstDayOfWeek(Calendar.THURSDAY);
first_day = calndr.getFirstDayOfWeek();
System.out.println( "The new first"
+ " day of the week: "
+ first_day);
}
}
|
Output:
The Current First day of the week: 1
The new first day of the week: 5
Example 2:
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
{
Calendar calndr
= new GregorianCalendar( 2018 , 6 , 10 );
int first_day = calndr.getFirstDayOfWeek();
System.out.println( "The"
+ " First day of the week: "
+ first_day);
calndr.setFirstDayOfWeek(Calendar.MONDAY);
first_day = calndr.getFirstDayOfWeek();
System.out.println( "The new first"
+ " day of the week: "
+ first_day);
}
}
|
Output:
The First day of the week: 1
The new first day of the week: 2
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#setFirstDayOfWeek-int-
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...