List of usage examples for java.text SimpleDateFormat setLenient
public void setLenient(boolean lenient)
From source file:org.apt.demo.util.Tools.java
public static Calendar convertString2Calendar(String s) { Calendar cal = null;//from w w w .j a va 2 s .com try { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); sdf.setLenient(false); Date d = sdf.parse(s); cal = Calendar.getInstance(); cal.setTimeInMillis(d.getTime()); } catch (Exception e) { e.printStackTrace(); return null; } return cal; }
From source file:Main.java
public static String getRelativeTimeAgo(String rawJsonDate) { String twitterFormat = "EEE MMM dd HH:mm:ss ZZZZZ yyyy"; SimpleDateFormat sf = new SimpleDateFormat(twitterFormat, Locale.ENGLISH); sf.setLenient(true); String relativeDate = ""; Date date;//from w w w. j a v a2s. c o m try { date = sf.parse(rawJsonDate); relativeDate = getTimeString(date); } catch (ParseException e) { e.printStackTrace(); } return relativeDate; }
From source file:nl.utwente.bigdata.GoalDefiner.java
private static SimpleDateFormat dateFormatter(String format) { TimeZone tz = TimeZone.getTimeZone("GMT"); SimpleDateFormat sf = new SimpleDateFormat(format, Locale.ENGLISH); sf.setTimeZone(tz);/*from w w w. j a v a2 s . c o m*/ sf.setLenient(true); return sf; }
From source file:jp.co.nemuzuka.utils.DateTimeChecker.java
/** * ?./*w ww .jav a2 s . c om*/ * @param target * @param patterns ? * @return true:?? false:????? */ private static boolean executeCheck(String target, String pattern) { if (StringUtils.isEmpty(target)) { return false; } if (target.length() != pattern.length()) { return false; } try { Integer.valueOf(target); } catch (NumberFormatException e) { return false; } SimpleDateFormat format = DateTimeUtils.createSdf(pattern); format.setLenient(false); try { format.parse(target); } catch (ParseException e) { return false; } return true; }
From source file:Main.java
public static DateFormat createDateFormat(String pattern, TimeZone timeZone, boolean strict) { if (pattern == null) { String msg = "The argument 'pattern' should not be null!"; throw new IllegalArgumentException(msg); }// ww w . j a v a2 s . co m final SimpleDateFormat sdf = new SimpleDateFormat(pattern); if (timeZone != null) { sdf.setTimeZone(timeZone); } sdf.setLenient(!strict); return sdf; }
From source file:Main.java
public static String formatExpirationDate(String text) { try {/*from www . j a v a2s . c o m*/ switch (text.length()) { case 1: int digit = Integer.parseInt(text); if (digit < 2) { return text; } else { return "0" + text + "/"; } case 2: int month = Integer.parseInt(text); if (month > 12 || month < 1) { // Invalid digit return text.substring(0, 1); } else { return text + "/"; } case 3: if (text.substring(2, 3).equalsIgnoreCase("/")) { return text; } else { text = text.substring(0, 2) + "/" + text.substring(2, 3); } case 4: int yearDigit = Integer.parseInt(text.substring(3, 4)); String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); int currentYearDigit = Integer.parseInt(year.substring(2, 3)); if (yearDigit < currentYearDigit) { // Less than current year invalid return text.substring(0, 3); } else { return text; } case 5: SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/yy"); simpleDateFormat.setLenient(false); Date expiry = simpleDateFormat.parse(text); if (expiry.before(new Date())) { // Invalid exp date return text.substring(0, 4); } else { return text; } default: if (text.length() > 5) { return text.substring(0, 5); } else { return text; } } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } // If an exception is thrown we clear out the text return ""; }
From source file:org.apache.syncope.core.misc.DataFormat.java
public static Date parseDate(final String source, final String conversionPattern) throws ParseException { SimpleDateFormat sdf = DATE_FORMAT.get(); sdf.applyPattern(conversionPattern); sdf.setLenient(false); return sdf.parse(source); }
From source file:de.terrestris.shogun.deserializer.DateDeserializer.java
/** * This method tries to convert a passed date string into a date. * * Currently only strings formatted as <code>dd.MM.yyyy HH:mm:ss</code> are * supported.//from ww w . j a v a 2s . co m * * @param jsonStr * @return a <code>Date</code>-object or null. */ public static Date parseCommonlyFormattedDate(String jsonStr) { SimpleDateFormat parserSDF = new SimpleDateFormat(DATE_FORMAT); parserSDF.setLenient(false); Date parsedDate = null; String failNotice = "Failed to parse string '" + jsonStr + "' with format '" + DATE_FORMAT + "'"; try { parsedDate = parserSDF.parse(jsonStr); } catch (ParseException e) { LOGGER.error(failNotice + ": " + e.getMessage()); } if (parsedDate == null) { LOGGER.info(failNotice); } return parsedDate; }
From source file:nl.ctmm.trait.proteomics.qcviewer.utils.Utilities.java
/** * Create a date format with the pattern "dd/MM/yyyy". * * @return the date format.//from w ww . java2 s. c o m */ public static SimpleDateFormat createDateFormat() { final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); dateFormat.setLenient(false); return dateFormat; }
From source file:org.hubiquitus.hubotsdk.adapters.HtwitterAdapter.TweetToHMessage.java
/*** * //from w ww . ja v a 2 s .c o m * @param date * @return Joda date * @throws ParseException */ public static java.util.Date getTwitterDate(String date) throws ParseException { final String TWITTER = "EEE MMM dd HH:mm:ss ZZZZZ yyyy"; SimpleDateFormat sf = new SimpleDateFormat(TWITTER); sf.setLenient(true); return sf.parse(date); }