当前位置: 首页>>代码示例>>Java>>正文


Java Calendar.setLenient方法代码示例

本文整理汇总了Java中java.util.Calendar.setLenient方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.setLenient方法的具体用法?Java Calendar.setLenient怎么用?Java Calendar.setLenient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Calendar的用法示例。


在下文中一共展示了Calendar.setLenient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ageTest2

import java.util.Calendar; //导入方法依赖的package包/类
@Test
@Points("93.1")
public void ageTest2() {
    Calendar nyt = Calendar.getInstance();

    nyt.setLenient(true);
    nyt.add(Calendar.YEAR, -1);

    int vuosi = nyt.get(Calendar.YEAR);
    int kuukausi = nyt.get(Calendar.MONTH) + 1;
    int paiva = nyt.get(Calendar.DATE);
    Person henkilo = new Person("Sälli", paiva, kuukausi, vuosi);
    int ika = henkilo.age();
    assertTrue("The age of person born year ago should be 1, "
            + "returned age was: " + ika, (ika == 1));
}
 
开发者ID:gengwg,项目名称:java_mooc_fi,代码行数:17,代码来源:PersonTest.java

示例2: getDay

import java.util.Calendar; //导入方法依赖的package包/类
public int getDay(int week, int dayOfWeek) {
    Calendar c = Calendar.getInstance(Locale.US);
    c.setTime(iForm.getSessionBeginDate());
    c.setLenient(true);
    c.add(Calendar.WEEK_OF_YEAR, week-1);
    c.add(Calendar.DAY_OF_WEEK, dayOfWeek - c.get(Calendar.DAY_OF_WEEK));
    Calendar ec = Calendar.getInstance(Locale.US);
    ec.setTime(iForm.getExamBeginDate());
    return c.get(Calendar.DAY_OF_YEAR)-ec.get(Calendar.DAY_OF_YEAR);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:11,代码来源:ExamGridTable.java

示例3: ageTest4

import java.util.Calendar; //导入方法依赖的package包/类
@Test
@Points("93.1")
public void ageTest4() {
    Calendar nyt = Calendar.getInstance();

    nyt.setLenient(true);
    nyt.add(Calendar.YEAR, -27);
    nyt.add(Calendar.MONTH, 5);
    nyt.add(Calendar.DATE, 27);

    int vuosi = nyt.get(Calendar.YEAR);
    int kuukausi = nyt.get(Calendar.MONTH) + 1;
    int paiva = nyt.get(Calendar.DATE);
    Person henkilo = new Person("Sälli", paiva, kuukausi, vuosi);
    int ika = henkilo.age();
    assertTrue("The age of person born more than 26 years ago but less than 27 years ago should be 26"
            + ". Returned age was: " + ika, (ika == 26));
}
 
开发者ID:gengwg,项目名称:java_mooc_fi,代码行数:19,代码来源:PersonTest.java

示例4: getCalendar

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * @return Ein Calendar mit Local CH_DE, Datum und Zeit sind undefiniert.
 */

protected static Calendar getCalendar() {

	Calendar calendar = Calendar.getInstance(LOCALE_DE_CH);
	calendar.setLenient(false);
	calendar.clear();
	return calendar;
}
 
开发者ID:dvbern,项目名称:date-helper,代码行数:12,代码来源:DateHelper.java

示例5: getDayOfWeek

import java.util.Calendar; //导入方法依赖的package包/类
public int getDayOfWeek(int day) {
    Calendar cal = Calendar.getInstance(Locale.US);
    cal.setTime(iForm.getExamBeginDate());
    cal.setLenient(true);
    cal.add(Calendar.DAY_OF_YEAR, day);
    return cal.get(Calendar.DAY_OF_WEEK);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:8,代码来源:ExamGridTable.java

示例6: getWeekName

import java.util.Calendar; //导入方法依赖的package包/类
public String getWeekName(int week) {
    Calendar c = Calendar.getInstance(Locale.US);
    c.setTime(iForm.getSessionBeginDate());
    c.setLenient(true);
    c.add(Calendar.WEEK_OF_YEAR, week-1);
    Formats.Format<Date> df = Formats.getDateFormat(Formats.Pattern.DATE_EVENT_SHORT);
    while (c.get(Calendar.DAY_OF_WEEK)!=Calendar.MONDAY) c.add(Calendar.DAY_OF_YEAR, -1);
    String first = df.format(c.getTime());
    while (c.get(Calendar.DAY_OF_WEEK)!=Calendar.SUNDAY) c.add(Calendar.DAY_OF_YEAR, 1);
    String end = df.format(c.getTime());
    return "Week "+week+"<br>"+first+" - "+end;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:13,代码来源:ExamGridTable.java

示例7: firstDate

import java.util.Calendar; //导入方法依赖的package包/类
protected static Date firstDate(DatePattern dp, int dayCode) {
   	if (dp == null) return null;
   	BitSet weekCode = dp.getPatternBitSet();
   	if (weekCode.isEmpty()) return null;
   	Calendar cal = Calendar.getInstance(Locale.US); cal.setLenient(true);
   	Date dpFirstDate = DateUtils.getDate(1, dp.getSession().getPatternStartMonth(), dp.getSession().getSessionStartYear());
   	cal.setTime(dpFirstDate);
   	int idx = weekCode.nextSetBit(0);
   	cal.add(Calendar.DAY_OF_YEAR, idx);
   	while (idx < weekCode.size()) {
   		if (weekCode.get(idx)) {
       		int dow = cal.get(Calendar.DAY_OF_WEEK);
       		switch (dow) {
       		case Calendar.MONDAY:
       			if ((dayCode & DayCode.MON.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.TUESDAY:
       			if ((dayCode & DayCode.TUE.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.WEDNESDAY:
       			if ((dayCode & DayCode.WED.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.THURSDAY:
       			if ((dayCode & DayCode.THU.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.FRIDAY:
       			if ((dayCode & DayCode.FRI.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.SATURDAY:
       			if ((dayCode & DayCode.SAT.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.SUNDAY:
       			if ((dayCode & DayCode.SUN.getCode()) != 0) return cal.getTime();
       			break;
       		}
       	}
   		cal.add(Calendar.DAY_OF_YEAR, 1); idx++;
   	}
   	return null;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:41,代码来源:ClassInfoConnector.java

示例8: getNumber

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * Parse the input string and return the corresponding calendar field
 * number.
 */
private static double getNumber(String in, String[] formats, int calField)
  throws ParseException
{
  Calendar cal = Calendar.getInstance();
  cal.setLenient(false);
  // Try the allowed formats, from longest to shortest.
  Date date = testFormats(in, formats);
  if (date == null) return Double.NaN;
  cal.setTime(date);
  return cal.get(calField);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:ExsltDatetime.java

示例9: isGeldigeKalenderdatum

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * Contoleer of de datum een geldige kalander datum is. Een (deels) onbekende datum is geen
 * geldige kalender datum.
 * @param datum String representatie van de datum 'yyyyMMdd'
 * @return true of false.
 */
public static boolean isGeldigeKalenderdatum(final Integer datum) {
    boolean geldig = datum != null && datum != 0;
    if (geldig) {
        try {
            final String datumString = datum.toString();
            final int jaar = Integer.parseInt(datumString.substring(0, 4));
            final int maand = Integer.parseInt(datumString.substring(4, 6));
            final int dag = Integer.parseInt(datumString.substring(6, 8));
            final Calendar c = new GregorianCalendar();
            c.setLenient(false);
            c.set(jaar, maand - 1, dag);
            c.getTime();
            geldig = true;
        } catch (final IllegalArgumentException e) {
            return false;
        }
    }
    return geldig;
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:26,代码来源:DatumUtil.java

示例10: Test4051765

import java.util.Calendar; //导入方法依赖的package包/类
public void Test4051765() {
    Calendar cal = Calendar.getInstance();
    cal.setLenient(false);
    cal.set(DAY_OF_WEEK, 0);
    try {
        cal.getTime();
        errln("Fail: DAY_OF_WEEK 0 should be disallowed");
    } catch (IllegalArgumentException e) {
        return;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:CalendarRegression.java

示例11: getDateOf

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * <p>
 * Get a <code>Date</code> object that represents the given time, on
 * today's date.
 * </p>
 * 
 * @param second
 *          The value (0-59) to give the seconds field of the date
 * @param minute
 *          The value (0-59) to give the minutes field of the date
 * @param hour
 *          The value (0-23) to give the hours field of the date
 * @return the new date
 */
public static Date getDateOf(int second, int minute, int hour) {
    validateSecond(second);
    validateMinute(minute);
    validateHour(hour);

    Date date = new Date();

    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.setLenient(true);

    c.set(Calendar.HOUR_OF_DAY, hour);
    c.set(Calendar.MINUTE, minute);
    c.set(Calendar.SECOND, second);
    c.set(Calendar.MILLISECOND, 0);

    return c.getTime();
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:33,代码来源:TriggerUtils.java

示例12: getWeek

import java.util.Calendar; //导入方法依赖的package包/类
public int getWeek(int day) {
    Calendar cal = Calendar.getInstance(Locale.US);
    cal.setTime(iForm.getExamBeginDate());
    cal.setLenient(true);
    cal.add(Calendar.DAY_OF_YEAR, day);
    int week = 1;
    while (cal.getTime().after(iForm.getSessionBeginDate()) && cal.get(Calendar.WEEK_OF_YEAR) != iForm.getSessionBeginWeek()) {
    	cal.add(Calendar.DAY_OF_YEAR, -7); week ++;
    }
    while (cal.getTime().before(iForm.getSessionBeginDate()) && cal.get(Calendar.WEEK_OF_YEAR) != iForm.getSessionBeginWeek()) {
    	cal.add(Calendar.DAY_OF_WEEK, 7); week --;
    }
    return week;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:15,代码来源:ExamGridTable.java

示例13: toDate

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * Convert a long value to the specified Date type for this
 * <i>Converter</i>.
 * <p>
 *
 * This method handles conversion to the following types:
 * <ul>
 *     <li><code>java.util.Date</code></li>
 *     <li><code>java.util.Calendar</code></li>
 *     <li><code>java.sql.Date</code></li>
 *     <li><code>java.sql.Time</code></li>
 *     <li><code>java.sql.Timestamp</code></li>
 * </ul>
 *
 * @param <T> The target type
 * @param type The Date type to convert to
 * @param value The long value to convert.
 * @return The converted date value.
 */
private <T> T toDate(final Class<T> type, final long value) {

    // java.util.Date
    if (type.equals(Date.class)) {
        return type.cast(new Date(value));
    }

    // java.sql.Date
    if (type.equals(java.sql.Date.class)) {
        return type.cast(new java.sql.Date(value));
    }

    // java.sql.Time
    if (type.equals(java.sql.Time.class)) {
        return type.cast(new java.sql.Time(value));
    }

    // java.sql.Timestamp
    if (type.equals(java.sql.Timestamp.class)) {
        return type.cast(new java.sql.Timestamp(value));
    }

    // java.util.Calendar
    if (type.equals(Calendar.class)) {
        Calendar calendar = null;
        if (locale == null && timeZone == null) {
            calendar = Calendar.getInstance();
        } else if (locale == null) {
            calendar = Calendar.getInstance(timeZone);
        } else if (timeZone == null) {
            calendar = Calendar.getInstance(locale);
        } else {
            calendar = Calendar.getInstance(timeZone, locale);
        }
        calendar.setTime(new Date(value));
        calendar.setLenient(false);
        return type.cast(calendar);
    }

    final String msg = toString(getClass()) + " cannot handle conversion to '"
               + toString(type) + "'";
    if (log().isWarnEnabled()) {
        log().warn("    " + msg);
    }
    throw new ConversionException(msg);
}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:66,代码来源:DateTimeConverter.java

示例14: parseExpires

import java.util.Calendar; //导入方法依赖的package包/类
/** Parse a date as specified in RFC 6265, section 5.1.1. */
private static long parseExpires(String s, int pos, int limit) {
  pos = dateCharacterOffset(s, pos, limit, false);

  int hour = -1;
  int minute = -1;
  int second = -1;
  int dayOfMonth = -1;
  int month = -1;
  int year = -1;
  Matcher matcher = TIME_PATTERN.matcher(s);

  while (pos < limit) {
    int end = dateCharacterOffset(s, pos + 1, limit, true);
    matcher.region(pos, end);

    if (hour == -1 && matcher.usePattern(TIME_PATTERN).matches()) {
      hour = Integer.parseInt(matcher.group(1));
      minute = Integer.parseInt(matcher.group(2));
      second = Integer.parseInt(matcher.group(3));
    } else if (dayOfMonth == -1 && matcher.usePattern(DAY_OF_MONTH_PATTERN).matches()) {
      dayOfMonth = Integer.parseInt(matcher.group(1));
    } else if (month == -1 && matcher.usePattern(MONTH_PATTERN).matches()) {
      String monthString = matcher.group(1).toLowerCase(Locale.US);
      month = MONTH_PATTERN.pattern().indexOf(monthString) / 4; // Sneaky! jan=1, dec=12.
    } else if (year == -1 && matcher.usePattern(YEAR_PATTERN).matches()) {
      year = Integer.parseInt(matcher.group(1));
    }

    pos = dateCharacterOffset(s, end + 1, limit, false);
  }

  // Convert two-digit years into four-digit years. 99 becomes 1999, 15 becomes 2015.
  if (year >= 70 && year <= 99) year += 1900;
  if (year >= 0 && year <= 69) year += 2000;

  // If any partial is omitted or out of range, return -1. The date is impossible. Note that leap
  // seconds are not supported by this syntax.
  if (year < 1601) throw new IllegalArgumentException();
  if (month == -1) throw new IllegalArgumentException();
  if (dayOfMonth < 1 || dayOfMonth > 31) throw new IllegalArgumentException();
  if (hour < 0 || hour > 23) throw new IllegalArgumentException();
  if (minute < 0 || minute > 59) throw new IllegalArgumentException();
  if (second < 0 || second > 59) throw new IllegalArgumentException();

  Calendar calendar = new GregorianCalendar(UTC);
  calendar.setLenient(false);
  calendar.set(Calendar.YEAR, year);
  calendar.set(Calendar.MONTH, month - 1);
  calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
  calendar.set(Calendar.HOUR_OF_DAY, hour);
  calendar.set(Calendar.MINUTE, minute);
  calendar.set(Calendar.SECOND, second);
  calendar.set(Calendar.MILLISECOND, 0);
  return calendar.getTimeInMillis();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:57,代码来源:Cookie.java

示例15: scheduleEventStart

import java.util.Calendar; //导入方法依赖的package包/类
/**
 * Starts TvTStartTask
 */
public void scheduleEventStart()
{
	try
	{
		Calendar currentTime = Calendar.getInstance();
		Calendar nextStartTime = null;
		Calendar testStartTime = null;
		for (String timeOfDay : Config.TVT_EVENT_INTERVAL)
		{
			// Creating a Calendar object from the specified interval value
			testStartTime = Calendar.getInstance();
			testStartTime.setLenient(true);
			String[] splitTimeOfDay = timeOfDay.split(":");
			testStartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTimeOfDay[0]));
			testStartTime.set(Calendar.MINUTE, Integer.parseInt(splitTimeOfDay[1]));
			// If the date is in the past, make it the next day (Example: Checking for "1:00", when the time is 23:57.)
			if (testStartTime.getTimeInMillis() < currentTime.getTimeInMillis())
			{
				testStartTime.add(Calendar.DAY_OF_MONTH, 1);
			}
			// Check for the test date to be the minimum (smallest in the specified list)
			if (nextStartTime == null || testStartTime.getTimeInMillis() < nextStartTime.getTimeInMillis())
			{
				nextStartTime = testStartTime;
			}
		}
		_task = new TvTStartTask(nextStartTime.getTimeInMillis());
		ThreadPoolManager.getInstance().executeTask(_task);
	}
	catch (Exception e)
	{
		_log.warning("TvTEventEngine[TvTManager.scheduleEventStart()]: Error figuring out a start time. Check TvTEventInterval in config file.");
	}
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:38,代码来源:TvTManager.java


注:本文中的java.util.Calendar.setLenient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。