Java Utililty Methods Date Parse

List of utility methods to do Date Parse

Description

The list of methods to do Date Parse are organized into topic(s).

Method

DateconvertDateFromString(String data)
convert Date From String
SimpleDateFormat dateFormat = new SimpleDateFormat(DD_MM_YYYY);
return dateFormat.parse(data);
DateconvertDateStringToDate(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;
...
StringconvertDateStringToDB(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;
LongconvertDateStringToMilliseconds(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();
StringconvertIntToDate(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());
StringconvertIntToDatePattern2(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());
StringconvertLongToDate(final long time)
convert Long To Date
final Date date = new Date();
date.setTime(time);
return formatDate(date);
DateconvertStringToDate(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);
DateconvertStringToDate(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);
DateconvertStringToDate(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;