Java Utililty Methods Date Format

List of utility methods to do Date Format

Description

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

Method

StringdateFormat(Date date, String format)
Retorna uma data formatada conforme String format passado
SimpleDateFormat sf = new SimpleDateFormat(format);
return sf.format(date);
StringdateFormat(Date date, String pattern)
date Format
if (date == null || isNullString(pattern)) {
    return "";
SimpleDateFormat format = new SimpleDateFormat(pattern);
return format.format(date);
StringdateFormat(Date date, String pattern)
date Format
if (pattern == null || "".equals(pattern.trim())) {
    pattern = DATE_PATTERN;
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
StringdateFormat(Date date, String pattern)
date Format
SimpleDateFormat df = new SimpleDateFormat(pattern);
return df.format(date);
StringdateFormat(DateFormat f, Date d)
Formats a Date into a date/time string.
synchronized (f) {
    return f.format(d);
DateFormatdateFormat(int grain, TimeZone timeZone)
date Format
SimpleDateFormat result = dateFormat(grain);
if (timeZone != null) {
    result = new SimpleDateFormat(result.toPattern());
    result.setTimeZone(timeZone);
return result;
StringdateFormat(java.util.Date date, String formatStr)
date Format
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(formatStr);
return sdf.format(date);
StringdateFormat(long time)
date Format
return dateFormat(new Date(time));
DatedateFormat(String date, String dateFormat)
date Format
if (date == null)
    return null;
SimpleDateFormat format = new SimpleDateFormat(dateFormat);
if (date != null)
    try {
        return format.parse(date);
    } catch (Exception ex) {
return null;
StringDateFormat(String dateStr, String oldPattern, String newPattern)
Date Format
SimpleDateFormat sdf = new SimpleDateFormat(oldPattern);
Date date = null;
try {
    date = sdf.parse(dateStr);
} catch (ParseException e) {
    e.printStackTrace();
    return "";
return new SimpleDateFormat(newPattern).format(date);