Code example for Time

Methods: format, set

0
 
    /** Caching of current user visible current month/day date */ 
    private String mUserMonthDayString;
 
    /** Caching of the last updated date. */ 
    private Time mCachedDate = new Time();
 
    /** Temp variable. Used to avoid object instantiation. */ 
    private Time mTempTime = new Time();
 
    /** Caching of date stamp of mCachedDate. Not user visible. Persisted. */ 
    private String mCachedDateString;
 
    public DateTracker(DateOrder dateOrder) {
        this.dateOrder = dateOrder;
        updateDate(); 
    } 
 
    /** Read today's date and cache values. */ 
    public void updateDate() { 
        mTempTime.setToNow();
        if (!DateUtil.isSameDate(mTempTime, mCachedDate)) {
            mCachedDate.set(mTempTime);
            mCachedDateString = DateUtil.dateToString(mCachedDate);
            mUserDayOfWeekString = mCachedDate.format("%A");
            // NOTE: this value is cached for performance. If underlying system date order is changed,  
            // it will be reflected in next app restart. 
            mUserMonthDayString = mCachedDate
                    .format(dateOrder.monthBeforeDay() ? "%b %d" : "%d %b");
        } 
    } 
 
    /** 
     * Return an unspecified time that is guaranteed to be today. Can change. Caller should not