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 aDate)
This method generates a string representation of a date based on the System Property 'dateFormat' in the format you specify on input
return getDateTime(getDatePattern(), aDate);
StringconvertDateToString(Date date)
Converts an instance of java.util.Date into a String using the date format: yyyy-MM-ddTHH:mm:ss.SSSZ.
return convertDateToString(date, true);
StringconvertDateToString(Date date)
convert Date To String
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int timezoneOffset = -(cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000);
int hour = Math.abs(timezoneOffset / 60);
int min = Math.abs(timezoneOffset % 60);
String dateTime = sdf.format(date);
String timeOffset = (timezoneOffset <= 0 ? "+" : "-") + (hour < 10 ? "0" : "") + hour + ":"
...
StringconvertDateToString(Date date)
Concert a date from a dto, to a String.
String stringDate = null;
if (date != null) {
    DateFormat df = DateFormat.getInstance();
    SimpleDateFormat sf = (SimpleDateFormat) df;
    sf.applyPattern("dd/MM/yyyy");
    stringDate = sf.format(date);
return stringDate;
...
StringconvertDateToString(Date date)
Convert a date to the standard String representation yyyy-MM-dd hh:mm a.
return threadLocalSimpleDateFormat.get().format(date);
StringconvertDateToString(Date date)
Converts the given date to the specified string pattern "yyyy-MM-dd HH:mm:ss";
String result = convertDateToString(date, TALEND_DATE_PATTERN);
return result;
StringconvertDateToString(Date date)
Return the UTC date and time in W3C format down to second (yyyy-MM-ddTHH:mm:ssZ).
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.format(date);
StringconvertDateToString(Date date, boolean millis)
convert Date To String
if (date == null) {
    return null;
} else {
    DateFormat df;
    if (millis) {
        df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    } else {
        df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
...
StringconvertDateToString(Date date, int addHours)
convert Date To String
Calendar cal = Calendar.getInstance(); 
cal.setTime(date); 
cal.add(Calendar.HOUR_OF_DAY, addHours); 
return convertDateToString(cal.getTime()); 
StringconvertDateToString(Date date, String dateFormat)
convert Date To String
if (date == null) {
    return null;
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
String dateStr = sdf.format(date);
return dateStr;