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

StringconvertDate2String8(Date time)
yyyyMMddHH
return sdf8.format(time);
StringconvertDateTimeToString(Date date)
convert Date Time To String
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
try {
    return dateFormat.format(date);
} catch (Exception e) {
    throw e;
StringconvertDateTo(Date date, String patternToUse)
Convert the given date in the given format.
if (date == null) {
    return null;
SimpleDateFormat formatter = new SimpleDateFormat();
formatter.setLenient(false);
formatter.applyPattern(patternToUse);
return formatter.format(date);
StringconvertDateToServerTimeZoneDate(DateFormat formatter, String timeZoneName, long milliSecond)
This will convert server date/time to specified Time zone date/time and return the date in specified format.
Long loginTimeZoneDate = milliSecond;
if (timeZoneName != null) {
    loginTimeZoneDate = convertDateToServerTimeZoneDateInMilliSec(timeZoneName, milliSecond);
return formatter.format(new Date(loginTimeZoneDate));
StringconvertDateToStr(Date d, String format)
convert Date To Str
SimpleDateFormat simpledateformat = new SimpleDateFormat(format);
String s;
try {
    s = simpledateformat.format(d).toString();
    return s;
} catch (Exception e) {
    s = "1900-01-01";
return s;
StringconvertDateToStr(Date date, String format)
Date convert to String
------------------------------
SimpleDateFormat f = new SimpleDateFormat(format, Locale.SIMPLIFIED_CHINESE);
return f.format(date);
StringconvertDateToString(final Date datum, final boolean withDay)
konvertiere ein Date in ein lesbareres format.
final Calendar calendar = Calendar.getInstance();
calendar.setTime(datum);
final SimpleDateFormat format = new SimpleDateFormat(DATE_TIME_FORMAT_PATTERN);
if (withDay) {
    return calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()) + " " 
            + format.format(datum);
} else {
    return format.format(datum);
...
StringconvertDateToString(java.util.Date dt, String pattern)
Convertidor de fechas a un patron dado
String formattedString = null;
try {
    SimpleDateFormat formatter = new SimpleDateFormat(pattern);
    formattedString = formatter.format(dt);
} catch (Exception e) {
    formattedString = "-";
return formattedString;
...
StringconvertDateToString(String dateFormat, Date date)
convert Date To String
SimpleDateFormat sf = new SimpleDateFormat(dateFormat);
String dateStr = "";
if (date == null) {
    return dateStr;
dateStr = sf.format(date);
return dateStr;
StringconvertDateToString(String mask, Date date)
This method generates a string representation of a date's date/time in the format you specify on input.
SimpleDateFormat df = null;
String returnValue = "";
if (date == null) {
} else {
    df = new SimpleDateFormat(mask);
    returnValue = df.format(date);
return returnValue;
...