Java Utililty Methods Date to Time

List of utility methods to do Date to Time

Description

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

Method

StringtoExtendedTime(Date date)
Formats the time portion of the given date in ISO8601 compatible format with delimiters.
SimpleDateFormat formatter = new SimpleDateFormat("HH':'mm':'ss");
return formatter.format(date);
StringtoGeneralizedTime(Date date)
to LDAP generalized time string
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
Date gmtDate;
if (fmt.getCalendar().getTimeZone().inDaylightTime(date))
    gmtDate = new Date(date.getTime() - fmt.getCalendar().getTimeZone().getRawOffset()
            - fmt.getCalendar().getTimeZone().getDSTSavings());
else
    gmtDate = new Date(date.getTime() - fmt.getCalendar().getTimeZone().getRawOffset());
return (fmt.format(gmtDate));
...
StringtoLocalDateTime(Date date)
This method returns a char from the specified date.
return new SimpleDateFormat(localDateTimeFormatString).format(date);
StringtoLocalTimeString(Date d)
to Local Time String
return d == null ? null : df.format(d);
StringtoMT4TimeString(Date date)
to MT Time String
Calendar c = Calendar.getInstance();
c.setTime(date);
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
return format.format(c.getTime());
StringtoSimpleDateTime(Date date)
to Simple Date Time
return createSimpleFormat().format(date);
StringtoTime(Date... date)
to Time
SimpleDateFormat simple = new SimpleDateFormat(FORMAT_2);
if (date.length > 0) {
    return simple.format(date[0]);
return simple.format(new Date());
StringtoTimeStr(Date date)
to Time Str
return toDateString(date, DEFAULT_FORMAT_TIME);
StringToTimeStr(Date dt)
To Time Str
if (dt == null)
    return "";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return sdf.format(dt);
StringtoTimeString(Date date)
to Time String
return timeOnlyFormatter.format(date);