当前位置: 首页>>代码示例>>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;未经允许,请勿转载。