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

CalendargetTime(Date date)
Derives a Calendar object from a Date object
return getTime(date.getTime());
StringgetTime(Date date)
get Time
return format(date, "HH:mm:ss");
intgetTime(Date date)
get Time
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
return hour * 10000 + minute * 100 + second;
longgetTime(Date date, boolean isEnd)
get Time
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
if (isEnd) {
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    calendar.set(Calendar.MILLISECOND, 999);
...
StringgetTime(Date date, String pattern, Locale locale)
get Time
SimpleDateFormat formatter = new SimpleDateFormat(pattern, locale);
return formatter.format(date);
longgetTime(Date dateParam)
get Time
if (dateParam == null) {
    throw new IllegalArgumentException("The dateParam  must not be null");
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(dateParam.getTime());
int hour = cal.get(Calendar.HOUR);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
...
StringgetTime(Date executionTime)
get Time
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
return formatter.format(executionTime);
byte[]getTime(Date timestamp)
Return a time in Davis Vantage Pro format (two bytes).
Calendar cal = Calendar.getInstance();
cal.setTime(timestamp);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int value = hour * 100 + minute;
return getBytes(value);
StringgetTime(Date trialTime)
get Time
return dateToString(trialTime, DF_HMS);
DategetTime(final Date date, final int day)
get Time
final Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + day);
return calendar.getTime();