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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。