Home » Java programming language

Java Calendar setFirstDayOfWeek() Method with Example

Calendar Class setFirstDayOfWeek() method: Here, we are going to learn about the setFirstDayOfWeek() method of Calendar Class with its syntax and example.
Submitted by Preeti Jain, on February 02, 2020

Calendar Class setFirstDayOfWeek() method

  • setFirstDayOfWeek() method is available in java.util package.
  • setFirstDayOfWeek() method is used to sets the first day of the week.
  • setFirstDayOfWeek() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
  • The return type of the method is void, it does not return anything.
  • setFirstDayOfWeek() method accepts only one parameter is of int type.
  • setFirstDayOfWeek() method does not throw an exception at the time of set first day of the week.

Syntax:

    public void setFirstDayOfWeek(int day);

Parameter(s):

  • int day – represents the value of the first day of the week.

Return value:

The return type of this method is void, it returns nothing.

Example:

// Java Program to demonstrate the example of
// void setFirstDayOfWeek(int day) method of Calendar

import java.util.*;

public class SetFirstDayOfWeek {
    public static void main(String args[]) {

        // Instantiating a Calendar object
        Calendar ca = Calendar.getInstance();

        System.out.println("ca: " + ca.getTime());

        // By using setFirstDayOfWeek(int fi) method is to 
        // set the first day of the week of this Calendar
        ca.setFirstDayOfWeek(4);

        // By using getFirstDayOfWeek() method is to
        // return the first day of the week
        int day = ca.getFirstDayOfWeek();

        // Display First day of the week
        System.out.println("ca.getFirstDayOfWeek(): " + day);
    }
}

Output

ca: Sun Feb 02 08:15:19 GMT 2020
ca.getFirstDayOfWeek(): 4



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.