Refine search
/** * Creates a new date formatter with Farrago specific options. Farrago * parsing is strict and does not allow values such as day 0, month 13, etc. * * @param format {@link SimpleDateFormat} pattern */ public static SimpleDateFormat newDateFormat(String format) { SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.ROOT); sdf.setLenient(false); return sdf; }
public synchronized static Date parseDate(SimpleDateFormat sdf, String string) { sdf.setLenient(false); try { return sdf.parse(string); } catch (Exception e) { // log.debug(string + " was not recognized by " + format.toString()); } return null; }
private boolean IsDate( String str ) { // TODO: What about other dates? Maybe something for a CRQ try { SimpleDateFormat fdate = new SimpleDateFormat( "yyyy/MM/dd" ); fdate.setLenient( false ); fdate.parse( str ); } catch ( Exception e ) { return false; } return true; }
public static Date parse(final String str) throws ParseException { SimpleDateFormat parser = new SimpleDateFormat(DATE_TIME_FORMAT, Locale.US); parser.setLenient(false); return parser.parse(str); } }
public Object newInstance() { SimpleDateFormat dateFormat = new SimpleDateFormat(formatString, locale); dateFormat.setLenient(lenient); return dateFormat; }
public static Date convertToDate(String input) { Date date = null; if(null == input) { return null; } else { Iterator var2 = dateFormats.iterator(); while(var2.hasNext()) { SimpleDateFormat format = (SimpleDateFormat)var2.next(); try { format.setLenient(false); date = format.parse(input); } catch (ParseException var5) { ; } if(date != null) { break; } } return date; } }
public static int decodeTime( String s, String dateFormat ) throws Exception { SimpleDateFormat f = new SimpleDateFormat( dateFormat ); TimeZone utcTimeZone = TimeZone.getTimeZone( "UTC" ); f.setTimeZone( utcTimeZone ); f.setLenient( false ); ParsePosition p = new ParsePosition( 0 ); Date d = f.parse( s, p ); if ( d == null ) { throw new Exception( "Invalid time value " + dateFormat + ": \"" + s + "\"." ); } return (int) d.getTime(); }
@Override protected SimpleDateFormat initialValue() { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); simpleDateFormat.setLenient(false); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return simpleDateFormat; } };
@Override public Person processItem(Object t) { System.out.println("processItem: " + t); StringTokenizer tokens = new StringTokenizer((String) t, ","); String name = tokens.nextToken(); String date; try { date = tokens.nextToken(); format.setLenient(false); format.parse(date); } catch (ParseException e) { return null; } return new Person(id++, name, date); } }
/** * * @param dateString * date string for parse * @param dateFormat * format which should be applied for string * @return {@link java.util.Date} converted from dateString by format * @throws ParseException * if we can not parse date string */ public static Date getDateFromStringByFormat( String dateString, String dateFormat ) throws ParseException { if ( dateFormat == null ) { throw new ParseException( "Unknown date format. Format is null. ", 0 ); } if ( dateString == null ) { throw new ParseException( "Unknown date string. Date string is null. ", 0 ); } SimpleDateFormat simpleDateFormat = new SimpleDateFormat( dateFormat ); simpleDateFormat.setLenient( false ); // Don't automatically convert invalid date. return simpleDateFormat.parse( dateString ); }
@Override protected SimpleDateFormat initialValue() { SimpleDateFormat val = new SimpleDateFormat("yyyy-MM-dd"); val.setLenient(false); // Without this, 2020-20-20 becomes 2021-08-20. val.setTimeZone(TimeZone.getTimeZone("UTC")); return val; }; };
private static Date parse_simple(String dateStr, ParseableSimpleDateFormat f, Locale locale) throws ParseException { SimpleDateFormat dateFormat = getDateFormat(f, locale); dateFormat.setLenient(false); return dateFormat.parse(dateStr); }
/** * Attempt to parse an input string with the allowed formats, returning * null if none of the formats work. */ private static Date testFormats (String in, String[] formats) throws ParseException { for (int i = 0; i <formats.length; i++) { try { SimpleDateFormat dateFormat = new SimpleDateFormat(formats[i]); dateFormat.setLenient(false); return dateFormat.parse(in); } catch (ParseException pe) { } } return null; }
public static String format(final Date date) { SimpleDateFormat parser = new SimpleDateFormat(DATE_TIME_FORMAT, Locale.US); parser.setLenient(false); return parser.format(date); }
public static Date convertToDate(String input) { Date date = null; if(null == input) { return null; } else { Iterator var2 = dateFormats.iterator(); while(var2.hasNext()) { SimpleDateFormat format = (SimpleDateFormat)var2.next(); try { format.setLenient(false); date = format.parse(input); } catch (ParseException var5) { ; } if(date != null) { break; } } return date; } }
/** * Get the full name or abbreviation of the month or day. */ private static String getNameOrAbbrev(String in, String[] formatsIn, String formatOut) throws ParseException { for (int i = 0; i <formatsIn.length; i++) // from longest to shortest. { try { SimpleDateFormat dateFormat = new SimpleDateFormat(formatsIn[i], Locale.ENGLISH); dateFormat.setLenient(false); Date dt = dateFormat.parse(in); dateFormat.applyPattern(formatOut); return dateFormat.format(dt); } catch (ParseException pe) { } } return ""; } /**
/** * return a lenient date format set to GMT time zone. * @param pattern the pattern used for date/time formatting. * @return the configured format for this pattern. */ private static DateFormat createDateFormat(String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); TimeZone gmt = TimeZone.getTimeZone("GMT"); sdf.setTimeZone(gmt); sdf.setLenient(true); return sdf; }
/** * <p>Checks if the field is a valid date. The pattern is used with * <code>java.text.SimpleDateFormat</code>. If strict is true, then the * length will be checked so '2/12/1999' will not pass validation with * the format 'MM/dd/yyyy' because the month isn't two digits. * The setLenient method is set to <code>false</code> for all.</p> * * @param value The value validation is being performed on. * @param datePattern The pattern passed to <code>SimpleDateFormat</code>. * @param strict Whether or not to have an exact match of the datePattern. * @return true if the date is valid. */ public boolean isValid(String value, String datePattern, boolean strict) { if (value == null || datePattern == null || datePattern.length() <= 0) { return false; } SimpleDateFormat formatter = new SimpleDateFormat(datePattern); formatter.setLenient(false); try { formatter.parse(value); } catch(ParseException e) { return false; } if (strict && (datePattern.length() != value.length())) { return false; } return true; }
@InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }
SimpleDateFormat parser = new SimpleDateFormat(); parser.setLenient(lenient); ParsePosition pos = new ParsePosition(0); for (int i = 0; i < parsePatterns.length; i++) { Date date = parser.parse(str2, pos); if (date != null && pos.getIndex() == str2.length()) { return date;