FileDocCategorySizeDatePackage
DateFormatUtils.javaAPI DocAndroid 1.5 API3044Wed May 06 22:42:46 BST 2009com.android.phone

DateFormatUtils

public class DateFormatUtils extends Object
Date and time formatting utilities for the Phone app.

Fields Summary
Constructors Summary
private DateFormatUtils()
This class is never instantiated.

    
Methods Summary
private static voidappendAbbevYear(java.lang.StringBuilder buf, int year)

        buf.append(", ");

        year = year % 100;
        if (year < 10) {
            buf.append('0");
        }

        buf.append(year);
    
public static java.lang.StringformatCallTime(long when, boolean abbrev)

        Calendar c = new GregorianCalendar();

        c.setTimeInMillis(when);
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DATE);
        int hour = c.get(Calendar.HOUR);
        int minutes = c.get(Calendar.MINUTE);
        int amPm = c.get(Calendar.AM_PM);
        StringBuilder str = new StringBuilder("");

        if (hour == 0) {
            hour = 12;
        }
        str.append(hour);
        str.append(':");
        if (minutes < 10) {
            str.append('0");
        }
        str.append(minutes);
        str.append((amPm == 0) ? "am" : "pm");
        str.append("  ");

        str.append(DateUtils.getMonthString(month, DateUtils.LENGTH_SHORT));
        str.append(" ");
        str.append(day);

        if (abbrev) {
            Calendar c2 = new GregorianCalendar();
            int currentYear = c2.get(Calendar.YEAR);
            if (currentYear != year) {
                appendAbbevYear(str, year);
            }
        } else {
            appendAbbevYear(str, year);
        }

        return str.toString();
    
public static java.lang.StringformatDurationTime(int duration)

        int secondsPerHour = 3600;
        int hours = duration / secondsPerHour;
        int mins = (duration % secondsPerHour) / 60;
        int secs = duration % 60;

        StringBuilder buf = new StringBuilder();
        timeFormatHelper(buf, hours, true);
        timeFormatHelper(buf, mins, true);
        timeFormatHelper(buf, secs, false);

        return buf.toString();
    
private static voidtimeFormatHelper(java.lang.StringBuilder buf, int t, boolean appendColon)

        if (t < 10) {
            buf.append('0");
        }

        buf.append(t);

        if (appendColon) {
            buf.append(':");
        }