Java.util.Calendar.getMaximum() Method


Advertisements


Description

The java.util.Calendar.getMaximum() method returns the maximum value for the given calendar field.

Declaration

Following is the declaration for java.util.Calendar.getMaximum() method

public abstract int getMaximum(int field)

Parameters

field − the calendar field.

Return Value

The method returns the maximum value for the calendar field entered.

Exception

NA

Example

The following example shows the usage of java.util.calendar.getMaximum(field) method.

Live Demo
package com.tutorialspoint;

import java.util.*;

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

      // create a calendar
      Calendar cal = Calendar.getInstance();

      // return the maximum value for days
      int max = cal.getMaximum(Calendar.DAY_OF_WEEK);
      System.out.println("Maximum days  :" + max);

      // return the maximum value for months
      max = cal.getMaximum(Calendar.MONTH);
      System.out.println("Maximum months  :" + max);
   }
}

Let us compile and run the above program, this will produce the following result −

Maximum days  :7
Maximum months  :11

java_util_calendar.htm

Advertisements
E-Books Store