Code example for Calendar

Methods: format, setTimeInMillis

0
         * requests a tick on the next hard-second boundary 
         */ 
        mTicker = new Runnable() {
                public void run() { 
                    if (mTickerStopped) return;
                    mCalendar.setTimeInMillis(System.currentTimeMillis());
                    setText(DateFormat.format(mFormat, mCalendar));
                    invalidate();
                    long now = SystemClock.uptimeMillis();
                    long next = now + (1000 - now % 1000);
                    mHandler.postAtTime(mTicker, next);
                } 
            }; 
        mTicker.run();
    } 
 
    @Override 
    protected void onDetachedFromWindow() { 
        super.onDetachedFromWindow(); 
        mTickerStopped = true;
    }