List of utility methods to do String to Date
Date | toDate(String date, String format) Parses the given date according to format and returns it as java.util.Date instance.
if (date == null || format == null) throw new IllegalArgumentException("Neither date, not format can be null!"); DateFormat timeStampFormat = new SimpleDateFormat(format); Date result = timeStampFormat.parse(date); return result; |
Date | toDate(String date, String format) to Date Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, 0); c.set(Calendar.MONTH, 0); c.set(Calendar.DAY_OF_MONTH, 1); c.set(Calendar.HOUR, 12); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); ... |
Date | toDate(String dateStr) This function is use to convert string date format to data format return toDate(dateStr, null);
|
Date | toDate(String dateStr) to Date SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); try { return sdf.parse(dateStr); } catch (Exception e) { return null; |
Date | toDate(String dateStr, String format) to Date return getSimpleDateFormat(format).parse(dateStr);
|
Date | toDate(String dateStr, String pattern) to Date SimpleDateFormat sdf = new SimpleDateFormat(pattern); try { return sdf.parse(dateStr); } catch (ParseException e) { return null; |
Date | toDate(String dateString) Attempts to convert a String representation of a date to a java.util.Date object. Date date = null; DateFormat df = DateFormat.getDateInstance(); try { df = DateFormat.getDateInstance(DateFormat.SHORT); date = df.parse(dateString); } catch (Exception e) { try { df = DateFormat.getDateInstance(DateFormat.MEDIUM); ... |
Date | toDate(String dateString) to Date if (Strings.isNullOrEmpty(dateString)) { return null; try { return DATE_FORMAT.parse(dateString); } catch (ParseException e) { throw new RuntimeException(e); |
Date | toDate(String dateString) to Date DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format.parse(dateString); |
Date | toDate(String dateString, Locale locale) This method parses a @param String dateString to a Date DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, locale); Date d = df.parse(dateString, new ParsePosition(0)); return d; |