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


Java GregorianCalendar.getActualMaximum方法代碼示例

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


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

示例1: getMonthEndDate

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * 月最後一天
 * @param date
 * @return
 */
public static Date getMonthEndDate(Date date){
	GregorianCalendar c = new GregorianCalendar();
	c.setTime(date);
	int maxMonth = c.getActualMaximum(Calendar.DAY_OF_MONTH);
	c.set(Calendar.DAY_OF_MONTH, maxMonth);
	c.set(Calendar.HOUR_OF_DAY, 23);
	c.set(Calendar.MINUTE, 59);
	c.set(Calendar.SECOND, 59);
	return c.getTime();
}
 
開發者ID:xujeff,項目名稱:tianti,代碼行數:16,代碼來源:DateUtils.java

示例2: Test4166109

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * GregorianCalendar.getActualMaximum() does not account for first day of week.
 */
public void Test4166109() {
    /* Test month:
    *
    *      March 1998
    * Su Mo Tu We Th Fr Sa
    *  1  2  3  4  5  6  7
    *  8  9 10 11 12 13 14
    * 15 16 17 18 19 20 21
    * 22 23 24 25 26 27 28
    * 29 30 31
     */
    boolean passed = true;
    int field = WEEK_OF_MONTH;

    GregorianCalendar calendar = new GregorianCalendar(Locale.US);
    calendar.set(1998, MARCH, 1);
    calendar.setMinimalDaysInFirstWeek(1);
    logln("Date:  " + calendar.getTime());

    int firstInMonth = calendar.get(DAY_OF_MONTH);

    for (int firstInWeek = SUNDAY; firstInWeek <= SATURDAY; firstInWeek++) {
        calendar.setFirstDayOfWeek(firstInWeek);
        int returned = calendar.getActualMaximum(field);
        int expected = (31 + ((firstInMonth - firstInWeek + 7) % 7) + 6) / 7;

        logln("First day of week = " + firstInWeek
                + "  getActualMaximum(WEEK_OF_MONTH) = " + returned
                + "  expected = " + expected
                + ((returned == expected) ? "  ok" : "  FAIL"));

        if (returned != expected) {
            passed = false;
        }
    }
    if (!passed) {
        errln("Test failed");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:43,代碼來源:CalendarRegression.java

示例3: Test4167060

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * Calendar.getActualMaximum(YEAR) works wrong.
 *
 * Note: Before 1.5, this test case assumed that
 * setGregorianChange didn't change object's date. But it was
 * changed. See 4928615.
 */
public void Test4167060() {
    int field = YEAR;
    DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy G",
            Locale.US);

    int[][] dates = {
        // year, month, day of month
        {100, NOVEMBER, 1},
        {-99 /*100BC*/, JANUARY, 1},
        {1996, FEBRUARY, 29}};

    String[] id = {"Hybrid", "Gregorian", "Julian"};

    for (int k = 0; k < 3; ++k) {
        logln("--- " + id[k] + " ---");

        for (int j = 0; j < dates.length; ++j) {
            GregorianCalendar calendar = new GregorianCalendar();
            if (k == 1) {
                calendar.setGregorianChange(new Date(Long.MIN_VALUE));
            } else if (k == 2) {
                calendar.setGregorianChange(new Date(Long.MAX_VALUE));
            }
            calendar.set(dates[j][0], dates[j][1], dates[j][2]);
            format.setCalendar((Calendar) calendar.clone());

            Date dateBefore = calendar.getTime();

            int maxYear = calendar.getActualMaximum(field);
            logln("maxYear: " + maxYear + " for " + format.format(calendar.getTime()));
            logln("date before: " + format.format(dateBefore));

            int[] years = {2000, maxYear - 1, maxYear, maxYear + 1};

            for (int i = 0; i < years.length; i++) {
                boolean valid = years[i] <= maxYear;
                calendar.set(field, years[i]);
                Date dateAfter = calendar.getTime();
                int newYear = calendar.get(field);
                calendar.setTime(dateBefore); // restore calendar for next use

                logln(" Year " + years[i] + (valid ? " ok " : " bad")
                        + " => " + format.format(dateAfter));
                if (valid && newYear != years[i]) {
                    errln("  FAIL: " + newYear + " should be valid; date, month and time shouldn't change");
                } else if (!valid && newYear == years[i]) {
                    errln("  FAIL: " + newYear + " should be invalid");
                }
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:60,代碼來源:CalendarRegression.java


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