title: Android: How do I display an updating clock in a TextView
body: <p>have a clock I want to display in a TextView.</p>
  
  <p>I would have thought there was a few nice functions to do this, but I couldn't find anything.
  I ended up implementing my own way that uses a Handler. What I'm asking though, is there a better (more efficient) way to display a real time updating clock?</p>
  
  <pre><code>private Runnable mUpdateClockTask = new Runnable() {
     public void run() {
         setTime();
         mClockHandler.postDelayed(this, 1000);
     }
  };
  </code></pre>
  
  <p>That's my handler, which runs every second, and then my set time and date function is below</p>
  
  <pre><code>TextView mClockView;
  
  public void setTime() {
      Calendar cal = Calendar.getInstance();
      int minutes = cal.get(Calendar.MINUTE);
  
      if (DateFormat.is24HourFormat(this)) {
          int hours = cal.get(Calendar.HOUR_OF_DAY);
          mClockView.setText((hours &lt; 10 ? "0" + hours : hours) + ":" + (minutes &lt; 10 ? "0" + minutes : minutes));
      }
      else {
          int hours = cal.get(Calendar.HOUR);
          mClockView.setText(hours + ":" + (minutes &lt; 10 ? "0" + minutes : minutes) + " " + new DateFormatSymbols().getAmPmStrings()[cal.get(Calendar.AM_PM)]);
      }
  }
  </code></pre>
  
  <p>Cheers</p>