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

StringformatDate(Date date)
Method description
return formatDate(date, null);
StringformatDate(Date date)
format Date
return formatDate(date, "yyyy-MM-dd");
StringformatDate(Date date)
Formats a standard Java date into the MOCA date String (YYYYMMDDHHmmss) format.
if (date == null)
    return null;
DateFormat tmp = (DateFormat) _dateFormat.clone();
return tmp.format(date);
StringformatDate(Date date)
format date with the default pattern
SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
return format.format(date);
StringformatDate(Date date)
Formats a Date object to return a date using the global locale.
SimpleDateFormat outFormat = new SimpleDateFormat("yyyy-MM-dd");
return outFormat.format(date);
StringformatDate(Date date)
Converts Date to String.
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
return sdf.format(date);
StringformatDate(Date date)
Formats the date, returns a string in the format 2020-12-31T23:59:59.123Z
return new SimpleDateFormat(DATE_FORMAT).format(date);
StringformatDate(Date date, DateFormat dateFormat, char delimiter, boolean endWithDelimiter)
Formats the date according to the specified format and returns as a string.
Calendar cal = Calendar.getInstance(dateFormat.getTimeZone(), Locale.ENGLISH);
cal.setTime(date);
int offset = getOffsetInMinutes(cal);
StringBuilder sb = new StringBuilder(dateFormat.format(date));
appendOffset(sb, delimiter, offset, endWithDelimiter);
return sb.toString();
StringformatDate(Date date, Locale locale)
format Date
if (date == null) {
    return null;
DateFormat format = DateFormat.getDateInstance(DateFormat.FULL, locale);
return format.format(date);
StringformatDate(Date date, SimpleDateFormat dateFormat)
format Date
if (date != null) {
    return dateFormat.format(date);
} else {
    return null;