List of utility methods to do Date Parse
Date | convertDateFromString(String data) convert Date From String SimpleDateFormat dateFormat = new SimpleDateFormat(DD_MM_YYYY); return dateFormat.parse(data); |
Date | convertDateStringToDate(String dateString, String format) convert Date String To Date SimpleDateFormat sdf = new SimpleDateFormat(format); Date date = null; try { date = sdf.parse(dateString); } catch (ParseException e) { e.printStackTrace(); return date; ... |
String | convertDateStringToDB(String date) converts date string to db format string (yyyy-MM-dd HH:mm:ss) GregorianCalendar origDate = new GregorianCalendar(); SimpleDateFormat sdf1 = new SimpleDateFormat(DATE_FORMAT); origDate.setTime(sdf1.parse(date)); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_DB); String dbFormattedDate = sdf.format(origDate.getTime()); return dbFormattedDate; |
Long | convertDateStringToMilliseconds(String dateString) convert Date String To Milliseconds SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:SS"); Date date = formatter.parse(dateString); return date.getTime(); |
String | convertIntToDate(int date) convert Int To Date SimpleDateFormat sdf = new SimpleDateFormat("M-d HH:mm"); Long x = Long.valueOf(date) * 1000; Calendar c = Calendar.getInstance(); c.setTimeInMillis(x); return sdf.format(c.getTime()); |
String | convertIntToDatePattern2(int date) convert Int To Date Pattern SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Long x = Long.valueOf(date) * 1000; Calendar c = Calendar.getInstance(); c.setTimeInMillis(x); return dateFormat.format(c.getTime()); |
String | convertLongToDate(final long time) convert Long To Date final Date date = new Date(); date.setTime(time); return formatDate(date); |
Date | convertStringToDate(String aMask, String strDate) This method generates a string representation of a date/time in the format you specify on input SimpleDateFormat df = null; Date date = null; df = new SimpleDateFormat(aMask); try { date = df.parse(strDate); } catch (ParseException pe) { throw new IllegalArgumentException(pe.getMessage() + " " + pe.getErrorOffset()); return (date); |
Date | convertStringToDate(String aMask, String strDate) This method generates a string representation of a date/time in the format you specify on input SimpleDateFormat df = null; Date date = null; df = new SimpleDateFormat(aMask); try { date = df.parse(strDate); } catch (ParseException pe) { return null; return (date); |
Date | convertStringToDate(String arg) Converts string to Date using Default date format DateFormat df = getIsoFormat(); Date d = null; try { d = df.parse(arg); } catch (ParseException e) { return d; |