.getCalendarType()
Published Oct 28, 2023
Contribute to Docs
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
Contribute to Docs
- 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.
Learn Java on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly17 hours