List of utility methods to do String to Date
Date | stringToDateForIng(String date_str) string To Date For Ing SimpleDateFormat format = new SimpleDateFormat(datePatternForIng); try { return format.parse(date_str); } catch (ParseException e) { throw new Exception("errors.date.invalid"); |
Date | StringToDateFormat(String str, String format) String To Date Format Date dt = new Date(); if (str != null && !str.equals("")) { SimpleDateFormat transFormat = new SimpleDateFormat(format); dt = transFormat.parse(str); return dt; |
Date | stringToDateInTimeZone(String time, String timeZone) string To Date In Time Zone SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMddHHmm"); dateFormat.setTimeZone(TimeZone.getTimeZone(timeZone)); Date d = null; try { d = dateFormat.parse(time); } catch (ParseException e) { e.printStackTrace(); return d; |
Date | stringToDateMetaData(String dateString) String to date meta data. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.S"); try { return sdf.parse(dateString); } catch (NullPointerException ex) { return null; } catch (ParseException ex) { return null; |
Date | stringToDateTemporalCoverage(String dateString) string To Date Temporal Coverage SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { return sdf.parse(dateString); } catch (NullPointerException ex) { return null; } catch (ParseException ex) { return null; |
Date | stringToDatetime(String str, String format) string To Datetime if (str == null || str.equals("")) return null; SimpleDateFormat sdf = new SimpleDateFormat(format); try { return sdf.parse(str); } catch (ParseException e) { e.printStackTrace(); return null; ... |
Date | stringToDatetime(String string) string To Datetime DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date dateTime = dateFormat.parse(string); return dateTime; |
Date | stringToDateTime(String stringDate, String format) string To Date Time if (stringDate == null) { return null; try { return getFormat(format).parse(stringDate); } catch (ParseException e) { throw new RuntimeException(e); |
Date | stringToDateWithFormat(String stringToConvert, String dateFormat) string To Date With Format if (stringToConvert != null) { try { DateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); Date date = simpleDateFormat.parse(stringToConvert); return date; } catch (ParseException e) { return new Date(0); |
Date | strMSShortToDate(String str_date) str MS Short To Date try { return (Date) formatterMSShort.parse(str_date); } catch (Exception e) { System.out.println("StrToDateSSShort Exception :" + e + " " + str_date); return null; |