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

StringconvertDateToString(Date date, String format)
convert Date To String
SimpleDateFormat df = new SimpleDateFormat(format);
return df.format(date);
StringconvertDateToString(Date date, String pattern)
convert Date To String
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
StringconvertDateToString(Date date, String pattern)
convert Date To String
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
if (date == null) {
    return "";
try {
    return dateFormat.format(date);
} catch (Exception e) {
    e.printStackTrace();
...
StringconvertDateToString(Date date, String patternString, Locale locale)
convert Date To String
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(patternString, locale);
return simpleDateFormat.format(date);
StringconvertDateToString(Date dateObject, String dateFormat)
Method to convert the Date to String, Format of date to be specified.
if (dateObject == null || isStringBlank(dateFormat)) {
    return null;
SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
StringBuilder nowYYYYMMDD = new StringBuilder(dateFormatter.format(dateObject));
return nowYYYYMMDD.toString();
StringconvertDateToStringByFormat(Date date)
convert Date To String By Format
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
StringconvertDateToStringT(final Date date)
convert Date To String T
String dateString = null;
dateString = date == null ? "" : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
return dateString;
StringconvertDateToStringUI(Date data)
convert Date To String UI
if (data == null)
    return null;
String date = null;
try {
    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    date = formatter.format(data);
} catch (Exception e) {
    System.err.println(e.getMessage());
...
StringconvertDateToText(Date date)
Convert custom field value to text form
if (date != null) {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    return formatter.format(date);
return null;
StringconvertDateToUTC(Date date)
Converts the given date to the UTC time zone so that dates can be correctly converted on the client side
SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat.format(date);