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

StringextractTimeFromDate(Date date)
extract Time From Date
SimpleDateFormat printFormat = new SimpleDateFormat("HH:mm:ss");
return printFormat.format(date); 
StringgetFriendlyTime(Date dateTime)
get Friendly Time
StringBuffer sb = new StringBuffer();
Date current = Calendar.getInstance().getTime();
long diffInSeconds = (current.getTime() - dateTime.getTime()) / 1000;
long sec = (diffInSeconds >= 60 ? diffInSeconds % 60 : diffInSeconds);
long min = (diffInSeconds = (diffInSeconds / 60)) >= 60 ? diffInSeconds % 60 : diffInSeconds;
long hrs = (diffInSeconds = (diffInSeconds / 60)) >= 24 ? diffInSeconds % 24 : diffInSeconds;
long days = (diffInSeconds = (diffInSeconds / 24)) >= 30 ? diffInSeconds % 30 : diffInSeconds;
long months = (diffInSeconds = (diffInSeconds / 30)) >= 12 ? diffInSeconds % 12 : diffInSeconds;
...
StringgetFriendlyTimeString(Date date)
get Friendly Time String
return friendlyTimeFormat.format(date);
StringgetMediumDateString(Date date, boolean includeTime)
Returns medium date string representation in localized format (e.g.
if (includeTime) {
    return getDateTimeString(date, DateFormat.MEDIUM, DateFormat.SHORT);
} else {
    return getDateString(date, DateFormat.MEDIUM);
StringgetMSDateTimeString(Date date)
MSTYPE yyyy-MM-dd hh:mm:ss return
String result = null;
if (date != null) {
    result = msfLong.format(date);
return result;
StringgetTime(Date date)
get Time
SimpleDateFormat formatter_f = new SimpleDateFormat("yyyy-MM-dd");
String str = formatter_f.format(date);
return str;
StringgetTime(Date date)
get Time
String DATE_FORMAT = "HH:mm:ss";
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT);
String formattedTime = sdf.format(date);
return formattedTime;
String[]getTime(Date date)
get Time
String[] time = new String[2];
Calendar cal = Calendar.getInstance();
cal.setTime(date);
time[0] = Integer.toString(cal.get(Calendar.HOUR_OF_DAY));
time[1] = Integer.toString(cal.get(Calendar.MINUTE));
return time;
StringgetTime(Date date)
Return the current Time
return new SimpleDateFormat("HH:mm:ss").format(date);
StringgetTime(Date date)
get Time
sFormat = new SimpleDateFormat(TIME_FORMAT, Locale.CHINA);
return sFormat.format(date);