List of usage examples for java.text SimpleDateFormat setLenient
public void setLenient(boolean lenient)
From source file:org.akaza.openclinica.core.form.StringUtil.java
public static boolean isValidDate(String s) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.setLenient(false); try {/*from w ww.ja va 2 s. c o m*/ java.util.Date date = sdf.parse(s); if (date.after(new java.util.Date())) { return false; // not a date in the past,for date of birth } } catch (ParseException fe) { return false; // format is wrong } return true; }
From source file:org.akaza.openclinica.core.form.StringUtil.java
public static boolean isSameDate(String dateFormat1, String dateFormat2, String dateStr, Locale locale) { SimpleDateFormat sdf1 = new SimpleDateFormat(dateFormat1, locale); sdf1.setLenient(false); SimpleDateFormat sdf2 = new SimpleDateFormat(dateFormat2, locale); sdf2.setLenient(false);/* ww w . ja va 2 s . c om*/ return sameDate(sdf1, sdf2, dateStr); }
From source file:org.akaza.openclinica.core.form.StringUtil.java
/** * Return true if a string can be parsed by the dateFormat with locale. * * @param s// w w w .j a v a 2 s . c om * @param dateFormat * @param locale * @return */ //ywang (Oct., 2011) public static boolean isDateFormatString(String s, String dateFormat, Locale locale) { String dateformat = parseDateFormat(dateFormat); SimpleDateFormat f = new SimpleDateFormat(dateformat, locale); f.setLenient(false); try { f.parse(s); return true; } catch (Exception ex) { return false; } }
From source file:org.springframework.extensions.webscripts.servlet.WebScriptServletResponse.java
/** * Helper to return a HTTP Date Formatter * /*from w ww . j ava 2s. com*/ * @return HTTP Date Formatter */ private static SimpleDateFormat getHTTPDateFormat() { if (s_dateFormat.get() != null) { return s_dateFormat.get(); } SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy kk:mm:ss zzz"); formatter.setLenient(false); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); s_dateFormat.set(formatter); return s_dateFormat.get(); }
From source file:libepg.epg.util.datetime.DateTimeFieldConverter.java
/** * ?????java.sql.Timestamp??? <br> * MJD ??16 16 ??????246?4210BCD???<br> * ?????????????1??? <br>//from ww w.j ava 2 s .c om * 93/10/13 12:45:00?0xC079124500???? * * @param source * @return ???Timestamp * @throws IndexOutOfBoundsException ?????5??? * @throws java.text.ParseException ??????1???????????????? * */ public static synchronized java.sql.Timestamp BytesToSqlDateTime(byte[] source) throws ParseException { if (source.length != 5) { throw new IndexOutOfBoundsException( "?????5????????" + " ?=" + Hex.encodeHexString(source)); } if (Arrays.equals(source, UNDEFINED_DATETIME_BLOCK.getData())) { throw new ParseException("?????????? ? = " + Hex.encodeHexString(source), 0); } StringBuilder sb = new StringBuilder(); byte[] mjd = new byte[2]; System.arraycopy(source, 0, mjd, 0, mjd.length); sb.append(mjdToString(mjd)); byte[] hms = new byte[3]; System.arraycopy(source, 2, hms, 0, hms.length); sb.append(BcdTimeToString(hms)); String dateStr = sb.toString(); java.text.SimpleDateFormat dateParser = new java.text.SimpleDateFormat(DATE_PATTERN); dateParser.setLenient(false); long dt = dateParser.parse(dateStr).getTime(); if (LOG.isTraceEnabled()) { LOG.trace(dt); } return new java.sql.Timestamp(dt); }
From source file:org.berlin.batch.bom.DataMessageFinder.java
public static Date toDate(final String date) throws ParseException { final String TWITTER = "EEE MMM dd HH:mm:ss ZZZZZ yyyy"; final SimpleDateFormat sf = new SimpleDateFormat(TWITTER); sf.setLenient(true); return sf.parse(date); }
From source file:org.ohmage.service.UploadValidationServices.java
/** * Validates the provided timestamp. The timestamp must be of the form * yyyy-MM-dd HH:mm:ss in SimpleDateFormat pattern parlance. * /*from w w w . j a v a 2s. co m*/ * @param date The date to validate. * @param errorMessageEmptyOrNull The error message to push into the * Request when validation fails because the timestamp is null or empty. * @param errorMessageInvalid The error message to push into the Request when * validation fails because the timestamp is malformed. * * @see java.util.SimpleDateFormat * @throws ServiceException if the timestamp is null or an unparseable ISO8601 timestamp */ public static void validateIso8601Timestamp(final String timestamp, final String errorMessageEmptyOrNull, final String errorMessageInvalid) throws ServiceException { if (StringUtils.isEmptyOrWhitespaceOnly(timestamp)) { throw new ServiceException(ErrorCode.SERVER_INVALID_TIMESTAMP, errorMessageEmptyOrNull); } SimpleDateFormat sdf = new SimpleDateFormat(ISO_8601_TIMESTAMP_PATTERN); sdf.setLenient(false); try { sdf.parse(timestamp); } catch (ParseException pe) { String msg = errorMessageInvalid + timestamp; throw new ServiceException(ErrorCode.SERVER_INVALID_TIMESTAMP, msg, pe); } }
From source file:com.github.rutvijkumar.twittfuse.Util.java
public static Date getTwitterDate(String date) { Date dt = new Date(); SimpleDateFormat sf = new SimpleDateFormat(TWITTER); sf.setLenient(true); try {/*ww w . j a v a 2 s .com*/ dt = sf.parse(date); } catch (ParseException e) { e.printStackTrace(); } return dt; }
From source file:org.openlegacy.terminal.mvc.web.DefaultGenericController.java
private static void registerPropertyEditors(DataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); }
From source file:tasly.greathealth.thirdparty.order.common.TaslyThirdUtils.java
public static boolean isValidDate(final String date) { boolean convertSuccess = true; // ??/?/??yyyy/MM/dd? final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try {/* www . j a va 2s . c o m*/ // lenientfalse. ?SimpleDateFormat??2007/02/29???2007/03/01 format.setLenient(false); format.parse(date); } catch (final ParseException e) { // e.printStackTrace(); // throw java.text.ParseExceptionNullPointerException?? convertSuccess = false; } catch (final NullPointerException e) { convertSuccess = false; } return convertSuccess; }