Java教程

Java Calendar getLeastMaximum()方法

java.util.Calendar类的getLeastMaximum()方法是一种抽象方法。对于指定为该方法参数的字段,此方法从所有最大值中返回最小值。它以整数形式的字段作为参数。并返回一个整数。

语法

public abstract int getLeastMaximum(int field)

参数

field-日历字段。

返回

返回指定日历字段的所有最大值中的最小值。

抛出

请勿抛出任何异常。

示例1

import java.util.*;
public class JavaCalendargetLeastMaximumExample1 extends GregorianCalendar {
    public static void main(String[] args) {
        // create a calendar
      Calendar mycal = new GregorianCalendar(1996, 10, 23);
        System.out.println(" Date :" + mycal.getTime() );
        // print the greatest min. for year field
      int outp1 = mycal.getLeastMaximum(Calendar.YEAR);
        System.out.println("The Least Maximum (Year) is: " + outp1);
        int outp2 = mycal.getLeastMaximum(Calendar.MONTH);
        System.out.println("The Least Maximum (Month) is: " + outp2);
        int outp3 = mycal.getLeastMaximum(Calendar.DAY_OF_WEEK);
        System.out.println("The Least Maximum (Day) is: " + outp3);
    }
}
输出:
Date :Sat Nov 23 00:00:00 PST 1996
The Least Maximum (Year) is: 292269054
The Least Maximum (Month) is: 11
The Least Maximum (Day) is: 7

示例2

import java.util.*;
public class JavaCalendargetLeastMaximumExample2 {
    public static void main(String[] args) {
        // create a calendar
      Calendar mycal = Calendar.getInstance();
        System.out.println(" Date :" + mycal.getTime() );
        int outp1 = mycal.getLeastMaximum(Calendar.YEAR);
        System.out.println("The Least Maximum (Year) is: " + outp1);
        int outp2 = mycal.getLeastMaximum(Calendar.MONTH);
        System.out.println("The Least Maximum (Month) is: " + outp2);
        int outp3 = mycal.getLeastMaximum(Calendar.DAY_OF_WEEK);
        System.out.println("The Least Maximum (Day) is: " + outp3);
        mycal.add(Calendar.YEAR, 2020);
        mycal.add(Calendar.MONTH, 9);
        mycal.add(Calendar.DAY_OF_WEEK, 23);
        System.out.println("Date :" + mycal.getTime() );
        int outp11 = mycal.getLeastMaximum(Calendar.YEAR);
        System.out.println("The Least Maximum (Year) is: " + outp11);
        int outp21 = mycal.getLeastMaximum(Calendar.MONTH);
        System.out.println("The Least Maximum (Month) is: " + outp21);
        int outp31 = mycal.getLeastMaximum(Calendar.DAY_OF_WEEK);
        System.out.println("The Least Maximum (Day) is: " + outp31);
    }
}
输出:
Date :Sun Aug 05 00:23:46 PDT 2018
The Least Maximum (Year) is: 292269054
The Least Maximum (Month) is: 11
The Least Maximum (Day) is: 7
 Date :Sat May 28 00:23:46 PDT 4039
The Least Maximum (Year) is: 292269054
The Least Maximum (Month) is: 11
The Least Maximum (Day) is: 7
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4