Android Utililty Methods Time Get

List of utility methods to do Time Get

Description

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

Method

StringgetCurrentTime()
get Current Time
SimpleDateFormat sdf = new SimpleDateFormat(
        "yyyy-MM-dd HH:mm:ss.SSS");
Date date = new Date(System.currentTimeMillis());
return sdf.format(date);
StringNow(String time)
Now
SimpleDateFormat formatter = new SimpleDateFormat(
        "yyyyMMdd  hhmmss");
SimpleDateFormat formatter2 = new SimpleDateFormat(
        "yyyy-MM-dd  hh:mm:ss");
Date curDate;
try {
    curDate = formatter.parse(time);
    return formatter2.format(curDate);
...
StringtoTime(int time)
to Time
time /= 1000;
int minute = time / 60;
int hour = minute / 60;
int second = time % 60;
minute %= 60;
return String.format("%02d:%02d", minute, second);
StringgetCurrentTime()
get Current Time
return getCurrentTime("yyyyMMddHHmmss");
StringintConvertTime(int hour, int minut)
int Convert Time
StringBuilder time = new StringBuilder();
time.append(hour / 10 % 10);
time.append(hour % 10);
time.append(":");
time.append(minut / 10 % 10);
time.append(minut % 10);
return time.toString();
StringgetCurrentTime(String format)
get Current Time
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new Date());
StringgetCurrentTimeString()
get Current Time String
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
String second = cal.get(Calendar.SECOND) < 10 ? "0"
        + cal.get(Calendar.SECOND) : "" + cal.get(Calendar.SECOND);
String minute = cal.get(Calendar.MINUTE) < 10 ? "0"
        + cal.get(Calendar.MINUTE) : "" + cal.get(Calendar.MINUTE);
String hour = cal.get(Calendar.HOUR_OF_DAY) < 10 ? "0"
        + cal.get(Calendar.HOUR_OF_DAY) : ""
...
StringgetCurrentDateTime()
get Current Date Time
return getFormatDateTime(new Date(), "yyyy-MM-dd HH:mm:ss");
StringgetCurrentTime()
get Current Time
return getFormatDateTime(new Date(), "yyyy-MM-dd HH:mm:ss");
StringgetFormatShortTime(Date date)
get Format Short Time
return getFormatDateTime(date, "yyyy-MM-dd");