List of usage examples for java.text SimpleDateFormat setLenient
public void setLenient(boolean lenient)
From source file:org.tsm.concharto.util.TimeRangeFormat.java
/** * Parses dates from a very wide variety of formats and precisions * @param text text to parse//w w w . j a va 2 s. c o m * @return Date date * @throws ParseException if there is a parsing problem */ private static Date parseDate(String text) throws ParseException { text = normalizeDateText(text); SimpleDateFormat sdf = new SimpleDateFormat(); sdf.setLenient(false); return DateUtils.parseDate(sdf, text, patterns); }
From source file:org.tsm.concharto.util.TimeRangeFormat.java
/** * Utility for checking precision of user entered dates * @param text date string/*from w ww.j a v a 2s . c om*/ * @param patterns array of patterns (see SimpleDateFormat) * @return true if the date is parseable using the provided pattern */ private static boolean isParseable(String text, String[] patterns) { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.setLenient(false); for (String pattern : patterns) { try { sdf.applyPattern(pattern); sdf.parse(text); return true; } catch (ParseException e) { //no action } } return false; }
From source file:com.prowidesoftware.swift.utils.SwiftFormatUtils.java
private static Calendar getCalendar(final String value, final String format) { if (value != null) { try {/*from w ww . j a va2s .c o m*/ final SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setLenient(false); final Date d = sdf.parse(value); final Calendar cal = new GregorianCalendar(); cal.setTime(d); return cal; } catch (final ParseException e) { log.log(java.util.logging.Level.WARNING, "Could not parse '" + value + "' with pattern '" + format + "'"); } } return null; }
From source file:util.android.util.DateUtils.java
/** * Try to parse an ordinal date in the format: * <p>/*from w w w . ja v a 2 s .c om*/ * Monday 1st July 2013 * <p> * SimpleDateFormat doesn't like st, nd, th, rd in dates so we modify the input String before processing. * * @param dateString * @param timezone * @return Date */ @SuppressLint("SimpleDateFormat") public static Date parseOrdinalDate(String dateString, TimeZone timezone) throws IllegalArgumentException { dateString = dateString.trim().replaceAll("([0-9]+)(?:st|nd|rd|th)?", "$1").replace(" ", " "); Date d = null; SimpleDateFormat sdf = new SimpleDateFormat(); for (String ordinalMask : ordinalMasks) { try { sdf.applyPattern(ordinalMask); sdf.setTimeZone(timezone); sdf.setLenient(true); d = sdf.parse(dateString, new ParsePosition(0)); if (d != null) break; } catch (Exception ignored) { } } if (d == null) throw new IllegalArgumentException(); return d; }
From source file:edu.psu.iam.cpr.core.api.helper.FindPersonHelper.java
/** * Parse a date string and return a Calendar object. * //from www. jav a2 s. c o m * @param dateString The date to parse (in MM-DD-YYYY or MM/DD/YYYY format) * @param lenient Should parsing be lenient * * @return a Calendar object * @throws ParseException if dateString is malformed */ public static final Date parseDateString(final String dateString, final boolean lenient) throws ParseException { LOG4J_LOGGER.debug("FPH: now = parseDateString for string = " + dateString); if (dateString == null) { throw new ParseException("Date string is null", 0); } SimpleDateFormat sdf = new SimpleDateFormat(CprProperties.INSTANCE.getProperties() .getProperty(CprPropertyName.CPR_FORMAT_PARTIAL_DATE.toString())); sdf.setLenient(lenient); Date d = sdf.parse(dateString.replace('-', '/').trim()); return d; }
From source file:jp.co.ctc_g.jse.core.validation.util.Validators.java
/** * Date?????//from ww w .j a v a2 s .c o m * @param suspect * @param pattern ?? * @param throwing true???????? * @return */ public static Date toDate(CharSequence suspect, String pattern, boolean throwing) { Date value = null; try { SimpleDateFormat sdf = new SimpleDateFormat(pattern); sdf.setLenient(false); value = sdf.parse(suspect.toString()); } catch (ParseException e) { L.debug("??({})????????????????", new Object[] { suspect }); if (throwing) { throw new IllegalArgumentException(e); } } return value; }
From source file:org.pentaho.reporting.libraries.docbundle.BundleUtilities.java
public static Date parseDate(final String date) { if (date.startsWith("PT")) { return parseDuration(date); }/* ww w . jav a2 s . c o m*/ final SimpleDateFormat dateFormat = new SimpleDateFormat(); dateFormat.setLenient(false); for (int i = 0; i < DATEFORMATS.length; i++) { try { final String dateformat = DATEFORMATS[i]; dateFormat.applyPattern(dateformat); return dateFormat.parse(date); } catch (ParseException e) { // ignore } } return null; }
From source file:us.mn.state.health.lims.common.util.DateUtil.java
public static java.sql.Date convertStringDateToSqlDate(String date, String stringLocale) throws LIMSRuntimeException { Locale locale = new Locale(stringLocale); String pattern = ResourceLocator.getInstance().getMessageResources().getMessage(locale, "date.format.formatKey"); SimpleDateFormat format = new SimpleDateFormat(pattern, locale); format.setLenient(false); java.sql.Date returnDate = null; if (!StringUtil.isNullorNill(date)) { try {//w w w.ja v a 2s . c o m returnDate = new java.sql.Date(format.parse(date).getTime()); } catch (ParseException e) { // bugzilla 2154 LogEvent.logError("DateUtil", "convertStringDateToSqlDate()", e.toString()); throw new LIMSRuntimeException("Error parsing date", e); } } return returnDate; }
From source file:org.jmesalive.dao.PresidentDao.java
public static Date getDate(String date) { try {//from ww w . jav a 2 s .c om SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy"); simpleDateFormat.setLenient(false); Calendar calendar = Calendar.getInstance(); calendar.setTime(simpleDateFormat.parse(date)); return new Date(calendar.getTimeInMillis()); } catch (ParseException e) { e.printStackTrace(); } return null; }
From source file:org.mifos.framework.util.helpers.DateUtils.java
public static Date getDate(String value, Locale dateLocale, String formatStr) { if (value != null && !value.equals("")) { try {/*from ww w .j a v a 2 s . c o m*/ SimpleDateFormat format = new SimpleDateFormat(formatStr, dateLocale); format.setLenient(false); return format.parse(value); } catch (Exception e) { throw new FrameworkRuntimeException(e); } } return null; }