Java Calendar getCalendarType()方法
java.util.Calendar类的getAvailableCalendarTypes()方法返回一个Set,其中包含Java运行时环境支持的所有可用日历类型的字符串集。它返回日历类型或日历的类名。
语法
public String getCalendarType()
参数
没有参数传递给该方法。
返回
返回日历类型或日历类型的类名。
抛出
不抛出任何异常。
示例1
import java.util.Calendar;
public class JavaCalendargetCalendarTypeExample1 {
public static void main(String[] args) {
// creating a calendar named as cal1
Calendar calinstance = Calendar.getInstance();
// Print the calendar type of calinstance instance of calendar class
System.out.println("Type of Calendar is " +
calinstance.getCalendarType());
}
}
输出:
Type of Calendar is Gregory
示例2
import java.util.GregorianCalendar;
public class JavaCalendargetCalendarTypeExample2 extends GregorianCalendar{
//extending Gregorianclass
public static void main(String[] args) {
// creating an instance of type GregorianCalendar
GregorianCalendar calinstance = (GregorianCalendar) GregorianCalendar.getInstance();
// getting the Calendar type using getCalendarType method.
System.out.println("Type of Calendar is: " +
calinstance.getCalendarType());
}
}
输出:
Type of Calendar is: gregory