Java中的DateFormat类的getCalendar()方法用于获取与此日期/时间格式对象关联的日历。
用法:
public Calendar getCalendar()
参数:该方法不带任何参数。
返回值:该方法为此DateFormat对象返回Calendar的实例。
以下程序说明了Java中getCalendar()方法的用法:
示例1:
// Java code to illustrate
// getCalendar() method
import java.text.*;
import java.util.*;
public class DateFormat_Demo {
public static void main(String[] argv)
{
// Initializing the first formatter
DateFormat DFormat
= DateFormat.getDateTimeInstance();
// String formatting
String str = DFormat.format(new Date());
// Displaying the Calendar
System.out.println(DFormat.getCalendar());
}
}
输出:
java.util.GregorianCalendar[time=1553691245240, areFieldsSet=true, areAllFieldsSet=true, lenient=true, zone=sun.util.calendar.ZoneInfo[id="Etc/UTC", offset=0, dstSavings=0, useDaylight=false, transitions=0, lastRule=null], firstDayOfWeek=1, minimalDaysInFirstWeek=1, ERA=1, YEAR=2019, MONTH=2, WEEK_OF_YEAR=13, WEEK_OF_MONTH=5, DAY_OF_MONTH=27, DAY_OF_YEAR=86, DAY_OF_WEEK=4, DAY_OF_WEEK_IN_MONTH=4, AM_PM=1, HOUR=0, HOUR_OF_DAY=12, MINUTE=54, SECOND=5, MILLISECOND=240, ZONE_OFFSET=0, DST_OFFSET=0]
示例2:
// Java code to illustrate
// getCalendar() method
import java.text.*;
import java.util.*;
public class DateFormat_Demo {
public static void main(String[] argv)
{
// Initializing the first formatter
DateFormat DFormat
= new SimpleDateFormat("MM/ dd/ yy");
// String formatting
String str = DFormat.format(new Date());
// Displaying the Calendar
System.out.println(DFormat.getCalendar());
}
}
输出:
java.util.GregorianCalendar[time=1553691264669, areFieldsSet=true, areAllFieldsSet=true, lenient=true, zone=sun.util.calendar.ZoneInfo[id="Etc/UTC", offset=0, dstSavings=0, useDaylight=false, transitions=0, lastRule=null], firstDayOfWeek=1, minimalDaysInFirstWeek=1, ERA=1, YEAR=2019, MONTH=2, WEEK_OF_YEAR=13, WEEK_OF_MONTH=5, DAY_OF_MONTH=27, DAY_OF_YEAR=86, DAY_OF_WEEK=4, DAY_OF_WEEK_IN_MONTH=4, AM_PM=1, HOUR=0, HOUR_OF_DAY=12, MINUTE=54, SECOND=24, MILLISECOND=669, ZONE_OFFSET=0, DST_OFFSET=0]
参考: https://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html#getCalendar()
相关用法
- Java DateFormat setTimeZone()用法及代码示例
- Java DateFormat setLenient()用法及代码示例
- Java DateFormat setCalendar()用法及代码示例
- Java DateFormat getTimeZone()用法及代码示例
- Java DateFormat isLenient()用法及代码示例
- Java DateFormat format()用法及代码示例
- Java DateFormat getTimeInstance()用法及代码示例
- Java DateFormat clone()用法及代码示例
- Java DateFormat hashCode()用法及代码示例
- Java DateFormat getDateTimeInstance()用法及代码示例
- Java DateFormat getDateInstance()用法及代码示例
- Java DateFormat getAvailableLocales()用法及代码示例
- Java DateFormat equals()用法及代码示例
- Java DateFormat parse(string , ParsePosition)用法及代码示例
- Java DateFormat format(Date obj)用法及代码示例
注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 DateFormat getCalendar() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。