本文整理了Java中java.util.Calendar.setLenient()
方法的一些代码示例,展示了Calendar.setLenient()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Calendar.setLenient()
方法的具体详情如下:
包路径:java.util.Calendar
类名称:Calendar
方法名:setLenient
[英]Sets whether this Calendar accepts field values which are outside the valid range for the field.
[中]设置此日历是否接受超出字段有效范围的字段值。
代码示例来源:origin: commons-lang/commons-lang
/**
* Sets the specified field to a date returning a new object.
* This does not use a lenient calendar.
* The original date object is unchanged.
*
* @param date the date, not null
* @param calendarField the calendar field to set the amount to
* @param amount the amount to set
* @return a new Date object set with the specified value
* @throws IllegalArgumentException if the date is null
* @since 2.4
*/
private static Date set(Date date, int calendarField, int amount) {
if (date == null) {
throw new IllegalArgumentException("The date must not be null");
}
// getInstance() returns a new object, so this method is thread safe.
Calendar c = Calendar.getInstance();
c.setLenient(false);
c.setTime(date);
c.set(calendarField, amount);
return c.getTime();
}
代码示例来源:origin: xalan/xalan
/**
* 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);
}
代码示例来源:origin: square/okhttp
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);
代码示例来源:origin: redisson/redisson
return calendar.getTime();
calendar.setLenient(false);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minutes);
return calendar.getTime();
代码示例来源:origin: org.apache.commons/commons-lang3
final Locale lcl = locale==null ?Locale.getDefault() : locale;
final ParsePosition pos = new ParsePosition(0);
final Calendar calendar = Calendar.getInstance(tz, lcl);
calendar.setLenient(lenient);
try {
if (fdp.parse(str, pos, calendar) && pos.getIndex()==str.length()) {
return calendar.getTime();
代码示例来源:origin: wildfly/wildfly
String time = timeFraction[0];
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(0);
calendar.setLenient(false);
calendar.set(Calendar.YEAR, Integer.parseInt(time.substring(0, 4)));
calendar.set(Calendar.MONTH, Integer.parseInt(time.substring(4, 6)) - 1);
calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(time.substring(6, 8)));
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.substring(8, 10)));
if (time.length() >= 12) calendar.set(Calendar.MINUTE, Integer.parseInt(time.substring(10, 12)));
return calendar.getTime();
代码示例来源:origin: org.arrahtec/osdq-core
public static java.util.Date secondIntoDate(long millisec) {
Calendar cal = Calendar.getInstance();
cal.setLenient(true);
cal.setTimeInMillis(millisec);
return cal.getTime();
}
代码示例来源:origin: org.arrahtec/osdq-core
public static long dateIntoSecond(java.util.Date date) {
if (date == null ) return 0;
Calendar cal = Calendar.getInstance();
cal.setLenient(true);
cal.setTime(date);
return cal.getTimeInMillis();
}
代码示例来源:origin: stackoverflow.com
public static boolean isvalidDate (int day, int month, int year)
Calendar calendar = Calendar.getInstance();
calendar.setLenient(false);
calendar.set(year, month, day, 0, 0, 0);
try {
date.getTime();
return true;
} catch (Exception e) {
return false;
}
}
代码示例来源:origin: com.helger/ph-mini-quartz
public static Date futureDate (final int interval, final EIntervalUnit unit)
{
final Calendar c = PDTFactory.createCalendar ();
c.setTime (new Date ());
c.setLenient (true);
c.add (_translate (unit), interval);
return c.getTime ();
}
代码示例来源:origin: languagetool-org/languagetool
private Calendar getDate(Map<String, String> args) {
int year = Integer.parseInt(getRequired("year", args));
int month = getMonthFromArguments(args);
int dayOfMonth = getDayOfMonthFromArguments(args);
Calendar calendar = getCalendar();
calendar.setLenient(false); // be strict about validity of dates
//noinspection MagicConstant
calendar.set(year, month, dayOfMonth, 0, 0, 0);
return calendar;
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Sets the specified field to a date returning a new object.
* This does not use a lenient calendar.
* The original {@code Date} is unchanged.
*
* @param date the date, not null
* @param calendarField the {@code Calendar} field to set the amount to
* @param amount the amount to set
* @return a new {@code Date} set with the specified value
* @throws IllegalArgumentException if the date is null
* @since 2.4
*/
private static Date set(final Date date, final int calendarField, final int amount) {
validateDateNotNull(date);
// getInstance() returns a new object, so this method is thread safe.
final Calendar c = Calendar.getInstance();
c.setLenient(false);
c.setTime(date);
c.set(calendarField, amount);
return c.getTime();
}
代码示例来源:origin: commons-beanutils/commons-beanutils
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);
代码示例来源:origin: prestodb/presto
return calendar.getTime();
calendar.setLenient(false);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minutes);
return calendar.getTime();
代码示例来源:origin: lealone/Lealone
private static long getTimeTry(boolean lenient, TimeZone tz, int year, int month, int day, int hour, int minute,
int second, int millis) {
Calendar c;
if (tz == null) {
c = getCalendar();
} else {
c = Calendar.getInstance(tz);
}
synchronized (c) {
c.clear();
c.setLenient(lenient);
setCalendarFields(c, year, month, day, hour, minute, second, millis);
return c.getTime().getTime();
}
}
代码示例来源:origin: org.arrahtec/osdq-core
public static java.util.Date secondIntoDate(long millisec, TimeZone tz) {
Calendar cal = Calendar.getInstance(tz);
cal.setLenient(true);
cal.setTimeInMillis(millisec);
return cal.getTime();
}
代码示例来源:origin: org.arrahtec/osdq-core
public static long dateIntoSecond(java.util.Date date, TimeZone tz) {
if (date == null ) return 0;
Calendar cal = Calendar.getInstance(tz);
cal.setLenient(true);
cal.setTime(date);
return cal.getTimeInMillis();
}
代码示例来源:origin: stackoverflow.com
Calendar calendar = Calendar.getInstance();
calendar.setLenient(true);
calendar.set(Calendar.DATE, 1);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
代码示例来源:origin: prestodb/presto
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);
代码示例来源:origin: languagetool-org/languagetool
private Calendar getDate(Map<String, String> args) {
int year = Integer.parseInt(getRequired("year", args));
int month = getMonthFromArguments(args);
int dayOfMonth = getDayOfMonthFromArguments(args);
Calendar calendar = getCalendar();
calendar.setLenient(false); // be strict about validity of dates
//noinspection MagicConstant
calendar.set(year, month, dayOfMonth, 0, 0, 0);
return calendar;
}
内容来源于网络,如有侵权,请联系作者删除!