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

StringgetTimeStr(Date date)
Returns "22:00" for param "2014-02-09 22:00"
return HOUR_DATE_FORMAT.format(date);
StringgetTimeString(String strTime)
get Time String
try {
    SimpleDateFormat formatter = new SimpleDateFormat(
            "yyyyMMddHHmmssSSSZ");
    Date d = formatter.parse(strTime);
    DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
    return df1.format(d);
} catch (ParseException e) {
    return strTime;
...
StringgetNowDateTime()
get Now Date Time
Date date = new Date();
return formatDate(date);
intgetTimeAsInt()
get Time As Int
Calendar cal = Calendar.getInstance();
java.text.SimpleDateFormat sdf = new SimpleDateFormat("HHmmss");
String cdate = sdf.format(cal.getTime());
return Integer.parseInt(cdate);
TimenowAsTime()
now As Time
Calendar objCurrentCalendar = Calendar.getInstance();
StringBuffer sbTimeString = new StringBuffer();
int iHourOfDay = objCurrentCalendar.get(Calendar.HOUR_OF_DAY);
int iMinute = objCurrentCalendar.get(Calendar.MINUTE);
int iSecond = objCurrentCalendar.get(Calendar.SECOND);
sbTimeString.append(iHourOfDay);
sbTimeString.append(":");
sbTimeString.append(iMinute);
...
CalendargetCurrentTimeCalendar()
get Current Time Calendar
Calendar calendar = Calendar.getInstance();
return calendar;
StringgetCurrentTimeStr()
get Current Time Str
return getTimeStr(System.currentTimeMillis());
StringgetCurrentTimeString()
get Current Time String
Calendar calendar = Calendar.getInstance();
return calendar.get(Calendar.HOUR_OF_DAY) + ":"
        + calendar.get(Calendar.MINUTE);
StringgetTime()
get Time
Calendar c = Calendar.getInstance();
int theHour = c.get(Calendar.HOUR_OF_DAY);
int theMinute = c.get(Calendar.MINUTE);
int theSecond = c.get(Calendar.SECOND);
return (new Time(theHour, theMinute, theSecond)).toString();
StringgetTime()
get Time
Calendar c = Calendar.getInstance();
int theHour = c.get(Calendar.HOUR_OF_DAY);
int theMinute = c.get(Calendar.MINUTE);
int theSecond = c.get(Calendar.SECOND);
return (new Time(theHour, theMinute, theSecond)).toString();