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


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


Calendar类中的getGreatestMinimum(int calndr_field)方法用于返回此Calendar实例的给定日历字段(int calndr_field)的最大值。

用法:

public abstract int getGreatestMinimum(int calndr_field)

参数:该方法采用一个参数calndr_field,该参数表示要操作的日历字段。


返回值:该方法返回此日历字段的最低最大值。

以下示例程序旨在说明Calendar类的getGreatestMinimum()方法的用法:
示例1:

// Java code to illustrate 
// getGreatestMinimum() method 
  
import java.util.*; 
public class Java_Calendar_Demo { 
    public static void main(String[] args) 
    { 
        // Creating a calendar 
        Calendar calndr = new GregorianCalendar(2018, 6, 10); 
  
        // Calculating the highest min value 
        int rslt = calndr.getGreatestMinimum(Calendar.YEAR); 
  
        // Displaying the highest min value 
        System.out.println("The minimum year is: " + rslt); 
    } 
}
输出:
The minimum year is: 1

示例2:

// Java code to illustrate 
// getGreatestMinimum() method 
  
import java.util.*; 
public class Java_Calendar_Demo { 
    public static void main(String[] args) 
    { 
        // Creating a calendar 
        Calendar calndr = Calendar.getInstance(); 
  
        // Calculating the highest min value 
        int rslt = calndr.getGreatestMinimum(Calendar.MONTH); 
  
        // Displaying the highest min value 
        System.out.println("The minimum month is: " + rslt); 
    } 
}
输出:
The minimum month is: 0

参考: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#getGreatestMinimum(int)



相关用法


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