Java Utililty Methods Parse Date

List of utility methods to do Parse Date

Description

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

Method

DateparseDateTimeString(String dateTimeString)
parse Date Time String
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
try {
    Date d = (Date) formatter.parse(dateTimeString);
    return d;
} catch (ParseException e) {
return null;
String[]parseDateToStr(Date date)
Parse Date to array of string
String strFormat = "ddMMyyyy";
SimpleDateFormat dateFormat = new SimpleDateFormat(strFormat);
String[] arrDate = new String[3];
String strDate = null;
if (date == null)
    return arrDate;
strDate = dateFormat.format(date);
arrDate[0] = strDate.substring(0, 2);
...
StringparseDateToString(Date date, String format)
This is method parse format date to string Version: OEP 1.1 History: DATE AUTHOR DESCRIPTION ------------------------------------------------- 26-March-2015 ThongDV Create new
try {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    return sdf.format(date);
} catch (Exception e) {
return "";
StringparseDateToString(Date date, String pattern)
Parses the Date in given format and returns the string representation.
String d = "";
if (date != null) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
    d = dateFormat.format(date);
return d;
StringparseDateToString(Date datetime)
parse Date To String
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date sDate = new java.util.Date(datetime.getTime());
return df.format(sDate);
StringparseDateToString(final Date date, final String dateFormat, final String lang)
Parses a date to a particular format and returns the formatted String .
Preconditions.checkNotNull(date);
Preconditions.checkNotNull(dateFormat);
Preconditions.checkNotNull(lang);
final Locale locale = new Locale(lang);
final SimpleDateFormat format = new SimpleDateFormat(dateFormat, locale);
return format.format(date);
DateparseDateValue(String value)
parse Date Value
try {
    return getTimeFormat().parse(value);
} catch (ParseException e) {
    throw new IllegalArgumentException("Expected date field of format '" + ISO_8601_DATE_FORMAT
            + "', but found value '" + value + "'.", e);
DateparseDateWithFormat(String date, SimpleDateFormat dateFormat, Date defaultDate)
parse Date With Format
try {
    return dateFormat.parse(date);
} catch (ParseException e) {
    e.printStackTrace();
return defaultDate;
DateparseDateWithLeniency(final String str, final Locale locale, final String[] parsePatterns, final boolean lenient)

Parses a string representing a date by trying a variety of different parsers.

if (str == null || parsePatterns == null) {
    throw new IllegalArgumentException("Date and Patterns must not be null");
SimpleDateFormat parser;
if (locale == null) {
    parser = new SimpleDateFormat();
} else {
    parser = new SimpleDateFormat("", locale);
...
DateparseDateWithoutTime(final String date)
parse Date Without Time
return parseDateWithoutTime(date, false);