List of utility methods to do String to Date
String | toDateString(long ms) to Date String return format(ms, "yyyy-MM-dd"); |
String | toDateString(String fmt, Date date) to Date String return new SimpleDateFormat(fmt).format(date); |
Date | toDateStyleBoth(String dateStr) to Date Style Both SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { return sdf.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); return null; |
Date | toDatetime(String sDate) to Datetime try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); return sdf.parse(sDate); } catch (ParseException e) { throw new RuntimeException(e); |
String | toDateTimeFormat(String input, String inputfmt, String outputfmt) to Date Time Format Date date = null; SimpleDateFormat infmt = new SimpleDateFormat(inputfmt); try { date = infmt.parse(input); } catch (ParseException e) { e.printStackTrace(); SimpleDateFormat outFormat = new SimpleDateFormat(outputfmt); ... |
String | toDateTimeSSSString(long datetime) to Date Time SSS String return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS").format(new java.util.Date(datetime)); |
String | toDateTimeString(java.util.Date date) Makes a combined data and time string in the format "MM/DD/YYYY HH:MM:SS" from a Date. if (date == null) return ""; String dateString = toDateString(date); String timeString = toTimeString(date); if (dateString != null && timeString != null) { return dateString + " " + timeString; } else { return ""; ... |
String | toDateTimeString(java.util.Date date) Makes a combined data and time string in the format "MM/DD/YYYY HH:MM:SS" from a Date. if (date == null) return ""; String dateString = toDateString(date); String timeString = toTimeString(date); if (dateString != null && timeString != null) return dateString + " " + timeString; else return ""; ... |
Date | toDateWithFormatString(String date, String format) Returns a Java representation of a date string. if (date == null) return null; try { return new SimpleDateFormat(format).parse(date); } catch (ParseException e) { throw new IllegalArgumentException( "Unable to parse date '" + date + "' using format string '" + format + "'", e); |
Date | toDateWithTimezone(String dateTime, String pattern) To date with timezone. Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.ENGLISH); date = sdf.parse(dateTime); return date; |