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


Java DateFormat.setLenient方法代码示例

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


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

示例1: parse

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * Parse a String into a <code>Calendar</code> object
 * using the specified <code>DateFormat</code>.
 *
 * @param sourceType The type of the value being converted
 * @param targetType The type to convert the value to
 * @param value The String date value.
 * @param format The DateFormat to parse the String value.
 *
 * @return The converted Calendar object.
 * @throws ConversionException if the String cannot be converted.
 */
private Calendar parse(final Class<?> sourceType, final Class<?> targetType, final String value, final DateFormat format) {
    logFormat("Parsing", format);
    format.setLenient(false);
    final ParsePosition pos = new ParsePosition(0);
    final Date parsedDate = format.parse(value, pos); // ignore the result (use the Calendar)
    if (pos.getErrorIndex() >= 0 || pos.getIndex() != value.length() || parsedDate == null) {
        String msg = "Error converting '" + toString(sourceType) + "' to '" + toString(targetType) + "'";
        if (format instanceof SimpleDateFormat) {
            msg += " using pattern '" + ((SimpleDateFormat)format).toPattern() + "'";
        }
        if (log().isDebugEnabled()) {
            log().debug("    " + msg);
        }
        throw new ConversionException(msg);
    }
    final Calendar calendar = format.getCalendar();
    return calendar;
}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:31,代码来源:DateTimeConverter.java

示例2: isValid

import java.text.DateFormat; //导入方法依赖的package包/类
@Override
public boolean isValid(CharSequence sequence, ConstraintValidatorContext context) {
    if (sequence == null || sequence.length() == 0) {
        return true;
    }

    final String value = sequence.toString();

    for (String pattern : annotation.patterns()) {
        final DateFormat format = new SimpleDateFormat(pattern);
        format.setLenient(annotation.lenient());

        try {
            format.parse(value);
            return true;
        } catch (@SuppressWarnings("unused") ParseException e) {
            continue;
        }

    }
    return false;
}
 
开发者ID:xlate,项目名称:validators,代码行数:23,代码来源:DateTimeValidator.java

示例3: parseDateFormat

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * Parses a string using {@link SimpleDateFormat} and a given pattern. This
 * method parses a string at the specified parse position and if successful,
 * updates the parse position to the index after the last character used.
 * The parsing is strict and requires months to be less than 12, days to be
 * less than 31, etc.
 *
 * @param s       string to be parsed
 * @param dateFormat Date format
 * @param tz      time zone in which to interpret string. Defaults to the Java
 *                default time zone
 * @param pp      position to start parsing from
 * @return a Calendar initialized with the parsed value, or null if parsing
 * failed. If returned, the Calendar is configured to the GMT time zone.
 */
private static Calendar parseDateFormat(String s, DateFormat dateFormat,
    TimeZone tz, ParsePosition pp) {
  if (tz == null) {
    tz = DEFAULT_ZONE;
  }
  Calendar ret = Calendar.getInstance(tz, Locale.ROOT);
  dateFormat.setCalendar(ret);
  dateFormat.setLenient(false);

  final Date d = dateFormat.parse(s, pp);
  if (null == d) {
    return null;
  }
  ret.setTime(d);
  ret.setTimeZone(UTC_ZONE);
  return ret;
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:33,代码来源:DateTimeUtils.java

示例4: parse

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * Convert the specified locale-sensitive input object into an output object of the
 * specified type.
 *
 * @param value The input object to be converted
 * @param pattern The pattern is used for the convertion
 * @return the converted Date value
 *
 * @throws org.apache.commons.beanutils.ConversionException
 * if conversion cannot be performed successfully
 * @throws ParseException if an error occurs parsing
 */
@Override
protected Object parse(final Object value, String pattern) throws ParseException {

    // Handle Date
    if (value instanceof java.util.Date) {
        return value;
    }

    // Handle Calendar
    if (value instanceof java.util.Calendar) {
        return ((java.util.Calendar)value).getTime();
    }

     if (locPattern) {
         pattern = convertLocalizedPattern(pattern, locale);
     }

     // Create Formatter - use default if pattern is null
     final DateFormat formatter = pattern == null ? DateFormat.getDateInstance(DateFormat.SHORT, locale)
                                            : new SimpleDateFormat(pattern, locale);
     formatter.setLenient(isLenient);


     // Parse the Date
    final ParsePosition pos = new ParsePosition(0);
    final String strValue = value.toString();
    final Object parsedValue = formatter.parseObject(strValue, pos);
    if (pos.getErrorIndex() > -1) {
        throw new ConversionException("Error parsing date '" + value +
                "' at position="+ pos.getErrorIndex());
    }
    if (pos.getIndex() < strValue.length()) {
        throw new ConversionException("Date '" + value +
                "' contains unparsed characters from position=" + pos.getIndex());
    }

    return parsedValue;
 }
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:51,代码来源:DateLocaleConverter.java

示例5: initialValue

import java.text.DateFormat; //导入方法依赖的package包/类
@Override protected DateFormat initialValue() {
  // RFC 2616 specified: RFC 822, updated by RFC 1123 format with fixed GMT.
  DateFormat rfc1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
  rfc1123.setLenient(false);
  rfc1123.setTimeZone(UTC);
  return rfc1123;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:HttpDate.java

示例6: initialValue

import java.text.DateFormat; //导入方法依赖的package包/类
@Override protected DateFormat initialValue() {
  // Date format specified by RFC 7231 section 7.1.1.1.
  DateFormat rfc1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
  rfc1123.setLenient(false);
  rfc1123.setTimeZone(UTC);
  return rfc1123;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:HttpDate.java

示例7: tryConvert

import java.text.DateFormat; //导入方法依赖的package包/类
public Date tryConvert(String text, String pattern) {
    DateFormat dateFormat = new SimpleDateFormat(pattern);
    dateFormat.setLenient(false);

    try {
        return dateFormat.parse(text);
    } catch (ParseException ex) {
        logger.debug(ex.getMessage(), ex);
    }

    return null;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:13,代码来源:DateConverter.java

示例8: getDateFormat

import java.text.DateFormat; //导入方法依赖的package包/类
protected DateFormat getDateFormat(Locale locale) {
	DateFormat dateFormat = createDateFormat(locale);
	if (this.timeZone != null) {
		dateFormat.setTimeZone(this.timeZone);
	}
	dateFormat.setLenient(this.lenient);
	return dateFormat;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:DateFormatter.java

示例9: getFormat

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * <p>Returns a <code>DateFormat</code> for the specified Locale.</p>
 *
 * @param locale The locale a <code>DateFormat</code> is required for,
 *        system default if null.
 * @return The <code>DateFormat</code> to created.
 */
protected Format getFormat(Locale locale) {

    DateFormat formatter = null;
    if (dateStyle >= 0 && timeStyle >= 0) {
        if (locale == null) {
            formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle);
        } else {
            formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
        }
    } else if (timeStyle >= 0) {
        if (locale == null) {
            formatter = DateFormat.getTimeInstance(timeStyle);
        } else {
            formatter = DateFormat.getTimeInstance(timeStyle, locale);
        }
    } else {
        int useDateStyle = dateStyle >= 0 ? dateStyle : DateFormat.SHORT;
        if (locale == null) {
            formatter = DateFormat.getDateInstance(useDateStyle);
        } else {
            formatter = DateFormat.getDateInstance(useDateStyle, locale);
        }
    }
    formatter.setLenient(false);
    return formatter;

}
 
开发者ID:Ilhasoft,项目名称:data-binding-validator,代码行数:35,代码来源:AbstractCalendarValidator.java

示例10: initBinder

import java.text.DateFormat; //导入方法依赖的package包/类
@InitBinder
public void initBinder(WebDataBinder binder) {
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	dateFormat.setLenient(true);
	binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
 
开发者ID:babymm,项目名称:mumu,代码行数:7,代码来源:SystemUserController.java

示例11: initialValue

import java.text.DateFormat; //导入方法依赖的package包/类
protected DateFormat initialValue() {
    DateFormat rfc1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
    rfc1123.setLenient(false);
    rfc1123.setTimeZone(HttpDate.access$000());
    return rfc1123;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:7,代码来源:HttpDate$1.java

示例12: setDateFromString

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * Sets the date from a string representation.
 * 
 * @param dateString
 *            the date to set
 * @throws MbedCloudException
 *             if string cannot be interpreted as a date
 */
public synchronized void setDateFromString(String dateString) throws MbedCloudException {
    final DateFormat format = REQUEST_DATE_FORMAT;
    format.setLenient(true);
    setDate(TranslationUtils.convertTimestamp(dateString, format));
}
 
开发者ID:ARMmbed,项目名称:mbed-cloud-sdk-java,代码行数:14,代码来源:ApiMetadata.java


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