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

StringgetTime(final Date time)
Builds a string in the SimpleDateFormat of yyyyMMdd'T'HHmmss
return OBEX_DATE_FORMAT.format(time);
StringgetTime(java.util.Date date)
get Time
return formatDateHMS(date);
StringgetTime(java.util.Date date)
get Time
return format(date, "HH:mm:ss");
StringgetTime(java.util.Date date)
get Time
return format(date, "HH:mm:ss");
LonggetTimeAsMilliSeconds(Date dateTime)
Returns the seconds of the time without date {Category} TimestampUtil {talendTypes} Long {param} Date(today): The timestamp within a timeframe.
if (dateTime != null) {
    java.util.Calendar c = java.util.Calendar.getInstance(Locale.GERMAN);
    c.setTime(dateTime);
    c.setTimeZone(getUTCTimeZone());
    c.set(java.util.Calendar.YEAR, 1970);
    c.set(java.util.Calendar.DAY_OF_YEAR, 1);
    return c.getTime().getTime();
} else {
...
StringgetTimeAsString(Date date)
get Time As String
String value = null;
if (date != null) {
    value = TIME_FORMAT.format(date);
return value;
StringgetTimeAsXsdDateTime(Date d)
Format the Date as xsd:DateTime.
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
SimpleDateFormat sdf2 = new SimpleDateFormat("Z");
String one = sdf1.format(d.getTime());
String offset = sdf2.format(d.getTime());
String offsetA = offset.substring(0, 3);
String offsetB = offset.substring(3);
return one + offsetA + ":" + offsetB;
longgetTimeBackInMillis(final int granularity, final int numberToBack, final Date date)
get Time Back In Millis
Calendar calendar = buildCalendar(date);
calendar.add(granularity, -numberToBack);
long timeBackInMillis = calendar.getTimeInMillis();
return timeBackInMillis;
LonggetTimeBoxValue(TimeZone zone, Date date)
Returns an appropriate value for the UTCTimeBox for a specified TimeZone and Date .
if (date == null)
    return null;
Calendar cal = GregorianCalendar.getInstance(zone);
cal.setTime(date);
int hours = cal.get(Calendar.HOUR_OF_DAY);
int minutes = cal.get(Calendar.MINUTE);
int seconds = cal.get(Calendar.SECOND);
int millis = cal.get(Calendar.MILLISECOND);
...
StringgetTimeByCustomPattern(Date date, String pattern)
get Time By Custom Pattern
return new SimpleDateFormat(pattern).format(date);