.getCalendarType()
The .getCalendarType()
method is available in the Calendar
class in Java. It is used to retrieve the type or format of the calendar represented by the Calendar
object. This method returns a string representing the calendar type, such as “gregory”, “japanese”, “buddhist”, etc. This method does not accept any arguments.
Syntax
someCalendar.getCalendarType()
someCalendar
: The given calendar to be addressed.
Example
The following code demonstrates how to use the .getCalendarType()
method to obtain and display the type of calendar used by the Calendar instance, which represents the default calendar for the current locale in Java.
import java.util.Calendar;public class MyClass {public static void main(String[] args) {// Create a Calendar instance representing the default calendar for the current localeCalendar calendar = Calendar.getInstance();// Get the calendar type and store it in a variableString calendarType = calendar.getCalendarType();// Display the calendar typeSystem.out.println("Type of Calendar is: " + calendarType);}}
This example returns the following output:
Type of Calendar is: gregory
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.