Java Utililty Methods Hour Format

List of utility methods to do Hour Format

Description

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

Method

StringformatDate(Date d, String pattern, TimeZone tz)
format Date
SimpleDateFormat df = new SimpleDateFormat(pattern);
df.setTimeZone(tz);
return df.format(d);
StringformatDate(Date d, TimeZone tz)
format Date
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm");
sdf.setTimeZone(tz);
return sdf.format(d) + dateOffset(d, tz);
StringformatDate(Date date, boolean includeTime)
Method formatDate.
if (date != null) {
    if (includeTime)
        return new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a").format(date);
    else
        return new SimpleDateFormat("MM/dd/yyyy").format(date);
} else
    return null;
StringformatDate(Date date, boolean time, boolean csv)
returns the date in string format.
StringBuilder sb = new StringBuilder("");
if (time) {
    if (csv)
        sb.append("MMM dd yyyy hh:mm a");
    else
        sb.append("MMM dd, yyyy hh:mm a");
} else {
    if (csv)
...
StringformatDate(Date date, boolean withTime)
Formats a given date object to a standard date string.
if (withTime)
    return new SimpleDateFormat(DATETIME_FORMAT).format(date);
else
    return new SimpleDateFormat(DATE_FORMAT).format(date);
StringformatDate(Date date, String dateFormat)
format Date
try {
    return new SimpleDateFormat(dateFormat).format(date);
} catch (Exception e) {
    return "";
StringformatDate(Date date, String expression)
format Date
if (isEmpty(expression)) {
    expression = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(expression);
return sdf.format(date);
StringformatDate(Date date, String format)
Format date by the format
if (date == null) {
    return null;
Format formatter = new SimpleDateFormat(format);
return formatter.format(date);
StringformatDate(Date date, String format)
format Date
if (format == null || "".equals(format)) {
    format = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(date);
StringformatDate(Date date, String format)
format Date
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(date);