Java Utililty Methods String to Date

List of utility methods to do String to Date

Description

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

Method

StringtoDateString(Date date, String format)
Date converted to string in specified format.
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(date);
StringtoDateString(Date date, String format)
to Date String
SimpleDateFormat sf = new SimpleDateFormat(format);
return sf.format(date);
StringtoDateString(Date date, String formatPattern)
Formats date instance using the provided date format pattern
if (date == null) {
    return "";
SimpleDateFormat format = new SimpleDateFormat(formatPattern);
return format.format(date);
StringtoDateString(Date date, TimeZone timezone)
to Date String
if (date == null)
    return null;
if (timezone == null)
    timezone = TimeZone.getDefault();
SimpleDateFormat dbFmt = new SimpleDateFormat("yyyy/MM/dd");
dbFmt.setTimeZone(timezone);
return dbFmt.format(date);
StringtoDateString(final Date date)
to Date String
return toDateString(date, defaultDatePattern);
StringtoDateString(java.util.Date date)
Makes a date String in the format MM/DD/YYYY from a Date
if (date == null)
    return "";
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
int year = calendar.get(Calendar.YEAR);
String monthStr;
...
StringtoDateString(java.util.Date date)
Makes a date String in the format MM/DD/YYYY from a Date
if (date == null)
    return "";
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
int year = calendar.get(Calendar.YEAR);
String monthStr;
...
StringtoDateString(java.util.Date date, String format)
Makes a date String in the given from a Date
if (date == null)
    return "";
SimpleDateFormat dateFormat = null;
if (format != null) {
    dateFormat = new SimpleDateFormat(format);
} else {
    dateFormat = new SimpleDateFormat();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return dateFormat.format(date);
StringtoDateString(java.util.Date date, String spe)
to Date String
if (date == null)
    return "";
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
int year = calendar.get(Calendar.YEAR);
String monthStr = "" + month;
...
StringtoDateString(long lval)
Returns the string for the given long as a date.
return dateFormat.format(new Date(lval));