Java Utililty Methods Date to String

List of utility methods to do Date to String

Description

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

Method

StringconvertDateToURLFormat(final String dateToBeConvert)
convert Date To URL Format
final SimpleDateFormat oldFormat = new SimpleDateFormat("dd MMMMMM yyyy", Locale.US);
final SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd");
String reformattedStr = "";
try {
    reformattedStr = newFormat.format(oldFormat.parse(dateToBeConvert));
} catch (final ParseException e) {
    e.printStackTrace();
return reformattedStr;
StringconvertStringoXSDString(Date date)
convert Stringo XSD String
if (date == null) {
    return null;
StringBuilder lexicalForm;
String dateTime = convertDateToString(date, false);
int len = dateTime.length() - 1;
if (dateTime.indexOf('.', len - 4) != -1) {
    while (dateTime.charAt(len - 1) == '0') {
...
StringconvertTimeToString(Date date, String pattern)
convert Time To String
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
StringconvertToString(Date date)
convert To String
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
    return formatter.format(date);
} catch (Exception e) {
    return null;
StringConvertToString(Date date, String format)
Converts a date object to a string using the specified format.
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(date);
StringconvertToString(Date date, String style)
convert To String
SimpleDateFormat df = new SimpleDateFormat(style);
return df.format(date);
StringconvertToString(java.util.Date date)
This method returns the string
java.text.SimpleDateFormat out = new java.text.SimpleDateFormat("dd-MMM-yy");
return out.format(date);
StringconvertToString(String format, Date date)
convert To String
if (date == null)
    return "";
SimpleDateFormat df = new SimpleDateFormat(format);
return df.format(date);
Stringdate2str(Calendar c)
datestr
return new SimpleDateFormat(DATE_FORMAT).format(c.getTime());
Stringdate2Str(Calendar c, String format)
date Str
if (c == null) {
    return null;
return date2Str(c.getTime(), format);