Calendar類中的internalGet(int calndr_field)方法用於返回給定日曆字段的值作為參數。
注意:該操作不涉及任何規範化或驗證。
用法:
protected final int internalGet(int calndr_field)
參數:該方法采用一個參數calndr_field,該參數表示要操作的日曆字段。
返回值:該方法返回傳遞的參數的值。
以下示例程序旨在說明Calendar類的internalGet()方法的用法:
示例1:
// Java code to illustrate
// internalGet() method
import java.util.*;
public class CalendarDemo
extends GregorianCalendar {
public static void main(String args[])
{
// Creating a new calendar
CalendarDemo calndr = new CalendarDemo();
// Displaying the Current date
System.out.println("The current date is: "
+ calndr.getTime());
// Getting the Month
System.out.println("Month is: "
+ calndr
.internalGet(MONTH));
// Getting the Year
System.out.println("Year is: "
+ calndr
.internalGet(YEAR));
}
}
輸出:
The current date is: Wed Feb 20 16:11:36 UTC 2019 Month is: 1 Year is: 2019
示例2:
// Java code to illustrate
// internalGet() method
import java.util.*;
public class Calendar_Demo
extends GregorianCalendar {
public static void main(String args[])
{
// Creating a calendar object
Calendar_Demo calndr = new Calendar_Demo();
// Displaying the current date
System.out.println("Calendar: "
+ calndr
.getTime());
// Displaying the year
System.out.println("Year: "
+ calndr
.internalGet(YEAR));
// Displaying the month
System.out.println("Month: "
+ calndr
.internalGet(MONTH));
// Displaying other credentials
System.out.println("Day: "
+ calndr
.internalGet(DAY_OF_WEEK));
}
}
輸出:
Calendar: Thu Feb 21 09:43:53 UTC 2019 Year: 2019 Month: 1 Day: 5
參考: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#internalGet-int-
相關用法
- Java Calendar get()用法及代碼示例
- Java Calendar set()用法及代碼示例
- Java Calendar add()用法及代碼示例
- Java Calendar isSet()用法及代碼示例
- Java Calendar getTimeZone()用法及代碼示例
- Java Calendar getInstance()用法及代碼示例
- Java Calendar getGreatestMinimum()用法及代碼示例
- Java Calendar getAvailableLocales()用法及代碼示例
- Java Calendar getDisplayName()用法及代碼示例
- Java Calendar getDisplayNames()用法及代碼示例
- Java Calendar getFirstDayOfWeek()用法及代碼示例
- Java Calendar getLeastMaximum()用法及代碼示例
- Java Calendar hashCode()用法及代碼示例
- Java Calendar getTime()用法及代碼示例
- Java Calendar roll()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Calendar internalGet() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。