Code example for Time

Methods: setToNow, switchTimezone, toMillis

0
      hand.draw(canvas);
      canvas.restore();
    } 
 
    private void onTimeChanged() { 
        mCalendar.setToNow();
 
        if (mTimeZoneId != null) {
            mCalendar.switchTimezone(mTimeZoneId);
        } 
 
        int hour = mCalendar.hour;
        int minute = mCalendar.minute;
        int second = mCalendar.second;
  //      long millis = System.currentTimeMillis() % 1000; 
 
        mSeconds = second;//(float) ((second * 1000 + millis) / 166.666);
        mMinutes = minute + second / 60.0f;
        mHour = hour + mMinutes / 60.0f;
        mChanged = true;
 
        updateContentDescription(mCalendar);
    } 
 
    private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
        @Override 
        public void onReceive(Context context, Intent intent) { 
            if (intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) { 
                String tz = intent.getStringExtra("time-zone"); 
                mCalendar = new Time(TimeZone.getTimeZone(tz).getID()); 
            } 
            onTimeChanged(); 
            invalidate(); 
        } 
    }; 
 
    private final Runnable mClockTick = new Runnable () {
 
        @Override 
        public void run() { 
            onTimeChanged(); 
            invalidate(); 
            AnalogClock.this.postDelayed(mClockTick, 1000); 
        } 
    }; 
 
    private void updateContentDescription(Time time) {
        final int flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR;
        String contentDescription = DateUtils.formatDateTime(mContext,
                time.toMillis(false), flags);
        setContentDescription(contentDescription);
    } 
 
    public void setTimeZone(String id) {
        mTimeZoneId = id;