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

DategetTimerDate(String time)
get Timer Date
String reg = "\\d{2}:\\d{2}:\\d{2}";
if (time.matches(reg)) {
    String[] temp = time.split(":");
    Calendar c = Calendar.getInstance();
    Date now = new Date();
    c.setTime(now);
    c.set(Calendar.HOUR, Integer.parseInt(temp[0]));
    c.set(Calendar.MINUTE, Integer.parseInt(temp[1]));
...
DategetTimeRoll(Date current, int field, int numberOfRoll)
get Time Roll
Calendar calendar = Calendar.getInstance();
calendar.setTime(current);
if (field == Calendar.DATE) {
    if (calendar.get(Calendar.DATE) == calendar.getActualMinimum(Calendar.DATE)) {
        if (calendar.get(Calendar.MONTH) == calendar.JANUARY) {
            if (numberOfRoll < 0) {
                calendar.roll(Calendar.MONTH, -1);
                calendar.roll(Calendar.YEAR, -1);
...
StringgetTimeStamp(long timeMilis, boolean time, boolean date)
get Time Stamp
return getTimeStamp(new StringBuilder(), timeMilis, time, date).toString();
StringgetTimeStampInMin(Date date)
get Time Stamp In Min
Calendar cal = Calendar.getInstance();
if (date != null)
    cal.setTime(date);
StringBuilder sb = new StringBuilder();
sb.append(cal.get(Calendar.YEAR));
sb.append(padding(cal.get(Calendar.MONTH) + 1));
sb.append(padding(cal.get(Calendar.DAY_OF_MONTH)));
sb.append("/");
...
StringgetTimeStampInSec(char separator, Date date)
get Time Stamp In Sec
Calendar cal = Calendar.getInstance();
if (date != null)
    cal.setTime(date);
StringBuilder sb = new StringBuilder();
sb.append(cal.get(Calendar.YEAR));
sb.append(separator);
sb.append(padding(cal.get(Calendar.MONTH) + 1));
sb.append(separator);
...
longgetTimestampl(Date time1, Date time2)
get Timestampl
if (time1 == null || time2 == null) {
    return 0;
Calendar cal = Calendar.getInstance();
cal.setTime(time1);
long m1 = cal.getTimeInMillis();
cal.setTime(time2);
long m2 = cal.getTimeInMillis();
...
StringgetTimeStr(Date date, char delimiter)
get Time Str
if (date != null) {
    DateFormat df = new SimpleDateFormat("HH" + delimiter + "mm");
    return df.format(date);
return "";
StringgetTimeString(Date d)

Returns string representation of time of day in format hh:mm a

if (d == null) {
    return "hh:mm";
} else {
    String dateString = null;
    try {
        SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
        dateString = formatter.format(d);
    } catch (Exception ex) {
...
StringgetTimeString(Date date)
HHmmss
DateFormat dateFormat = createNewDateFormat(timeFormat);
return formatDateString(date, dateFormat);
StringgetTimeString(Date self)

Return a string representation of the time portion of this date according to the locale-specific java.text.DateFormat#MEDIUM default format.

return DateFormat.getTimeInstance(DateFormat.MEDIUM).format(self);