當前位置: 首頁>>代碼示例>>Java>>正文


Java GregorianCalendar.getMaximum方法代碼示例

本文整理匯總了Java中java.util.GregorianCalendar.getMaximum方法的典型用法代碼示例。如果您正苦於以下問題:Java GregorianCalendar.getMaximum方法的具體用法?Java GregorianCalendar.getMaximum怎麽用?Java GregorianCalendar.getMaximum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.GregorianCalendar的用法示例。


在下文中一共展示了GregorianCalendar.getMaximum方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: dowTest

import java.util.GregorianCalendar; //導入方法依賴的package包/類
void dowTest(boolean lenient) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(1997, AUGUST, 12); // Wednesday
    cal.getTime(); // Force update
    cal.setLenient(lenient);
    cal.set(1996, DECEMBER, 1); // Set the date to be December 1, 1996
    int dow = cal.get(DAY_OF_WEEK);
    int min = cal.getMinimum(DAY_OF_WEEK);
    int max = cal.getMaximum(DAY_OF_WEEK);
    if (dow < min || dow > max) {
        errln("FAIL: Day of week " + dow + " out of range");
    }
    if (dow != SUNDAY) {
        errln("FAIL2: Day of week should be SUNDAY; is " + dow + ": " + cal.getTime());
    }
    if (min != SUNDAY || max != SATURDAY) {
        errln("FAIL: Min/max bad");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:CalendarTest.java

示例2: dowTest

import java.util.GregorianCalendar; //導入方法依賴的package包/類
void dowTest(boolean lenient) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(1997, AUGUST, 12); // Wednesday
    // cal.getTime(); // Force update
    cal.setLenient(lenient);
    cal.set(1996, DECEMBER, 1); // Set the date to be December 1, 1996
    int dow = cal.get(DAY_OF_WEEK);
    int min = cal.getMinimum(DAY_OF_WEEK);
    int max = cal.getMaximum(DAY_OF_WEEK);
    logln(cal.getTime().toString());
    if (min != SUNDAY || max != SATURDAY) {
        errln("FAIL: Min/max bad");
    }
    if (dow < min || dow > max) {
        errln("FAIL: Day of week " + dow + " out of range");
    }
    if (dow != SUNDAY) {
        errln("FAIL: Day of week should be SUNDAY Got " + dow);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:CalendarRegression.java

示例3: Test4145983

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * Maximum value for YEAR field wrong.
 */
public void Test4145983() {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
    Date[] DATES = {new Date(Long.MAX_VALUE), new Date(Long.MIN_VALUE)};
    for (int i = 0; i < DATES.length; ++i) {
        calendar.setTime(DATES[i]);
        int year = calendar.get(YEAR);
        int maxYear = calendar.getMaximum(YEAR);
        if (year > maxYear) {
            errln("Failed for " + DATES[i].getTime() + " ms: year="
                    + year + ", maxYear=" + maxYear);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:CalendarRegression.java

示例4: Test4147269

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * This is a bug in the validation code of GregorianCalendar.  As reported,
 * the bug seems worse than it really is, due to a bug in the way the bug
 * report test was written.  In reality the bug is restricted to the DAY_OF_YEAR
 * field. - liu 6/29/98
 */
public void Test4147269() {
    final String[] fieldName = {
        "ERA",
        "YEAR",
        "MONTH",
        "WEEK_OF_YEAR",
        "WEEK_OF_MONTH",
        "DAY_OF_MONTH",
        "DAY_OF_YEAR",
        "DAY_OF_WEEK",
        "DAY_OF_WEEK_IN_MONTH",
        "AM_PM",
        "HOUR",
        "HOUR_OF_DAY",
        "MINUTE",
        "SECOND",
        "MILLISECOND",
        "ZONE_OFFSET",
        "DST_OFFSET"};
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setLenient(false);
    @SuppressWarnings("deprecation")
    Date date = new Date(1996 - 1900, JANUARY, 3); // Arbitrary date
    for (int field = 0; field < FIELD_COUNT; field++) {
        calendar.setTime(date);
        // Note: In the bug report, getActualMaximum() was called instead
        // of getMaximum() -- this was an error.  The validation code doesn't
        // use getActualMaximum(), since that's too costly.
        int max = calendar.getMaximum(field);
        int value = max + 1;
        calendar.set(field, value);
        try {
            calendar.getTime(); // Force time computation
            // We expect an exception to be thrown. If we fall through
            // to the next line, then we have a bug.
            errln("Test failed with field " + fieldName[field]
                    + ", date before: " + date
                    + ", date after: " + calendar.getTime()
                    + ", value: " + value + " (max = " + max + ")");
        } catch (IllegalArgumentException e) {
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:50,代碼來源:CalendarRegression.java


注:本文中的java.util.GregorianCalendar.getMaximum方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。