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


Java GregorianCalendar.setLenient方法代碼示例

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


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

示例1: Test4401223a

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public void Test4401223a() {
    int status = 0;
    String s = null;

    try {
        @SuppressWarnings("deprecation")
        Date date = new Date(2000 - 1900, FEBRUARY, 29);
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.setLenient(false);
        gc.set(YEAR, 2001);
        s = "02/29/00 & set(YEAR,2001) = " + gc.getTime().toString();
    } catch (Exception ex) {
        status++;
        s = "Exception occurred for 2/29/00 & set(YEAR,2001): " + ex;
    }
    if (status > 0) {
        errln(s);
    } else {
        logln(s);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:bug4401223.java

示例2: main

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public static void main(String[] args) {
    for (int l = 0; l < locales.length; l++) {
        Locale loc = locales[l];
        for (int i = 0; i < offsets.length; i++) {
            test(loc, offsets[i][0], offsets[i][1]);
        }
    }

    // The test case in the bug report.
    GregorianCalendar cal = new GregorianCalendar();
    cal.setLenient(false);
    cal.setGregorianChange(new Date(Long.MIN_VALUE));
    cal.clear();
    cal.set(ZONE_OFFSET, 0);
    cal.set(DST_OFFSET, 0);
    cal.set(ERA, AD);
    cal.set(2004, FEBRUARY, 3, 0, 0, 0);
    cal.set(MILLISECOND, 0);
    // The following line should not throw an IllegalArgumentException.
    cal.getTime();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ZoneOffsets.java

示例3: 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

示例4: 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

示例5: getCalendar

import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
 * neues Calendar mit Datum und Zeit undefiniert.
 */
private static GregorianCalendar getCalendar() {

	GregorianCalendar cal = new GregorianCalendar();
	cal.setLenient(false);
	cal.clear();
	return cal;
}
 
開發者ID:dvbern,項目名稱:date-helper,代碼行數:11,代碼來源:FeiertageHelper.java

示例6: scheduleNotification

import java.util.GregorianCalendar; //導入方法依賴的package包/類
private void scheduleNotification() {
    if (reboot.equals("none")){
        return ;
    }
    GregorianCalendar rightNow = new GregorianCalendar();
    rightNow.setLenient(true);
    rightNow.setTime(new Date());

    long nowMillis =rightNow.getTimeInMillis();
    String[] rebootTime = reboot.split(":");
    rightNow.set(Calendar.HOUR_OF_DAY, Integer.parseInt(rebootTime[0]));
    rightNow.set(Calendar.MINUTE, Integer.parseInt(rebootTime[1]));
    rightNow.set(Calendar.SECOND, Integer.parseInt(rebootTime[2]));
    long  futureInMillis =rightNow.getTimeInMillis();
    if (futureInMillis < nowMillis){
        rightNow.add(Calendar.DAY_OF_MONTH, 1);
        futureInMillis =rightNow.getTimeInMillis();
    }
    final long delay =  futureInMillis - nowMillis;
    Log.d(TAG, "INTENT: set reboot at " + rightNow );
    Timer timer = new Timer();
    timer.schedule( new TimerTask(){
        @Override
        public void run() {
            rebootNow();
        }
    }, delay);
}
 
開發者ID:msillano,項目名稱:USBphpTunnel,代碼行數:29,代碼來源:SerialConsoleActivity.java

示例7: main

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public static void main(String[] args) {
    GregorianCalendar cal = new GregorianCalendar(2004, JANUARY, 1);
    cal.set(HOUR, 1);
    if (cal.get(HOUR_OF_DAY) != 1 ||
        cal.get(HOUR) != 1 || cal.get(AM_PM) != AM) {
        throw new RuntimeException("Unexpected hour of day: " + cal.getTime());
    }

    // Test case for 6440854
    GregorianCalendar gc = new GregorianCalendar(2006,5,16);
    gc.setLenient(false);
    gc.set(HOUR_OF_DAY, 10);
    // The following line shouldn't throw an IllegalArgumentException.
    gc.get(YEAR);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:Bug6178071.java

示例8: Test4401223b

import java.util.GregorianCalendar; //導入方法依賴的package包/類
public void Test4401223b() {
    int status = 0;
    String s = null;

    try {
        @SuppressWarnings("deprecation")
        Date date = new Date(2000 - 1900, DECEMBER, 31);
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(date);
        gc.setLenient(false);
        gc.set(YEAR, 2001);

        if (gc.get(YEAR) != 2001
                || gc.get(MONTH) != DECEMBER
                || gc.get(DATE) != 31
                || gc.get(DAY_OF_YEAR) != 365) {
            status++;
            s = "Wrong Date : 12/31/00 & set(YEAR,2001) ---> " + gc.getTime().toString();
        } else {
            s = "12/31/00 & set(YEAR,2001) = " + gc.getTime().toString();
        }
    } catch (Exception ex) {
        status++;
        s = "Exception occurred for 12/31/00 & set(YEAR,2001) : " + ex;
    }
    if (status > 0) {
        errln(s);
    } else {
        logln(s);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:bug4401223.java

示例9: SetDateToDisplay

import java.util.GregorianCalendar; //導入方法依賴的package包/類
@SimpleFunction(description = "Allows the user to set the date to be displayed when the date picker opens.\n" +
  "Valid values for the month field are 1-12 and 1-31 for the day field.\n")
public void SetDateToDisplay(int year, int month, int day) {
  int jMonth = month - 1;
  try {
    GregorianCalendar cal = new GregorianCalendar(year, jMonth, day);
    cal.setLenient(false);
    cal.getTime();
  } catch (java.lang.IllegalArgumentException e) {
    form.dispatchErrorOccurredEvent(this, "SetDateToDisplay", ErrorMessages.ERROR_ILLEGAL_DATE);
  }
  date.updateDate(year, jMonth, day);
  instant = Dates.DateInstant(year, month, day);
  customDate = true;
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:16,代碼來源:DatePicker.java

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