title: Android time 0:00 pm should be displaying 12:00 pm instead
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13891427/android-date-time-displaying-0-instead-of-12">Android date/time displaying 0 instead of 12</a>  </p>
  </blockquote>
  
  
  
  <p>Below is the code I use:</p>
  
  <pre><code>public void onTimeSet( TimePicker view, int selectedHour,
              int selectedMinute ) {
          // Gets current time
          Calendar c = Calendar.getInstance();
  
          hour = selectedHour;
          minute = selectedMinute;
  
          // set waking time into textview
          StringBuilder sb = new StringBuilder();
          if( hour &gt;= 12 ){                      
            sb.append(hour-12).append( ":" ).append(pad(minute)).append(" PM");
          }else if( hour == 0 ){
              sb.append( "12" ).append( ":" ).append( pad(minute) ).append( " AM" );
          } else if( hour == 24 ){
              sb.append(hour+24).append( ":" ).append( pad(minute) ).append( " PM" );
          }
  
          else{
            sb.append(hour).append( ":" ).append(pad(minute)).append(" AM");
          }
  
          // Assign hour set in the picker
          c.set( Calendar.HOUR, selectedHour );
          c.set( Calendar.MINUTE, selectedMinute );
  
          // Have Calendar calculate the substraction of hours and minutes
          c.add( Calendar.HOUR, SUB_HOUR );
          c.add( Calendar.MINUTE, SUB_MINUTE );
  
          // Get the hour and the minute calculated
          hour = c.get( Calendar.HOUR );
          minute = c.get( Calendar.MINUTE );
          //hour = c.get( Calendar.HOUR_OF_DAY );
  
          StringBuilder sb2 = new StringBuilder();
          if(hour&gt;=12){                      
            sb2.append(hour-12).append( ":" ).append(pad(minute)).append(" PM");
          }else if(hour == 0){
            sb2.append( "12" ).append( ":" ).append(pad(minute)).append( " AM" );
          }
          else{
            sb2.append(hour).append( ":" ).append(pad(minute)).append(" AM");
          }
  
          // set current time into textview
          answer.setText( "To wake up at " + sb + ", you must go to bed at " + sb2 );
  </code></pre>
  
  <p>In my first <strong>StringBuilder</strong>, when the user would choose 12:00 pm, it's displaying in 0:00 Pm not 12:00 pm, how can I do that? Thanks in advance.</p>