Calendar setFirstDayOfWeek() Method in Java with Examples
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:
// Java code to illustrate // setFirstDayOfWeek() method import java.util.*; public class Calendar_Demo { public static void main(String args[]) { // Creating calendar object Calendar calndr = Calendar.getInstance(); // Displaying first day of the week int first_day = calndr.getFirstDayOfWeek(); System.out.println( "The Current" + " First day of the week: " + first_day); // Changing the first day of week calndr.setFirstDayOfWeek(Calendar.THURSDAY); // Displaying the alternate day first_day = calndr.getFirstDayOfWeek(); System.out.println( "The new first" + " day of the week: " + first_day); } } |
The Current First day of the week: 1 The new first day of the week: 5
Example 2:
// Java code to illustrate // setFirstDayOfWeek() method import java.util.*; public class Calendar_Demo { public static void main(String args[]) { // Creating calendar object Calendar calndr = new GregorianCalendar( 2018 , 6 , 10 ); // Displaying first day of the week int first_day = calndr.getFirstDayOfWeek(); System.out.println( "The" + " First day of the week: " + first_day); // Changing the first day of week calndr.setFirstDayOfWeek(Calendar.MONDAY); // Displaying the alternate day first_day = calndr.getFirstDayOfWeek(); System.out.println( "The new first" + " day of the week: " + first_day); } } |
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-
Recommended Posts:
- Calendar set() Method in Java with Examples
- Calendar add() Method in Java with Examples
- Calendar get() method in Java with Examples
- Calendar getActualMinimum() Method in Java with Examples
- Calendar getActualMaximum() Method in Java with Examples
- Calendar getDisplayName() Method in Java with Examples
- Calendar setLenient() Method in Java with Examples
- Calendar getAvailableLocales() Method in Java with Examples
- Calendar setTime() Method in Java with Examples
- Calendar getLeastMaximum() method in Java with Examples
- Calendar setTimeInMillis() Method in Java with Examples
- Calendar getTimeZone() Method in Java with Examples
- Calendar internalGet() Method in Java with Examples
- Calendar complete() Method in Java with Examples
- Calendar computeTime() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.