当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Calendar internalGet()用法及代码示例


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-



相关用法


注:本文由纯净天空筛选整理自Chinmoy Lenka大神的英文原创作品 Calendar internalGet() Method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。