Android date/time displaying 0 instead of 12

Posted by bEtTy Barnes on Stack Overflow See other posts from Stack Overflow or by bEtTy Barnes
Published on 2012-12-15T10:33:44Z Indexed on 2012/12/15 11:04 UTC
Read the original article Hit count: 218

Filed under:
|
|

I wonder what's wrong with my code below:

 // Assign hour set in the picker
        c.set( Calendar.HOUR, selectedHour );
        c.set( Calendar.MINUTE, selectedMinute );

        // For alternative times
        c.add( Calendar.HOUR, SUB_SIX_HOUR );
        c.add( Calendar.MINUTE, SUB_FLAT_MINUTE );

        hour = c.get( Calendar.HOUR );
        minute = c.get( Calendar.MINUTE );
        hour = c.get( Calendar.HOUR_OF_DAY );

        StringBuilder sb4 = new StringBuilder();
        if(hour>=12){                      
          sb4.append(hour-12).append( ":" ).append(minute).append(" PM");
        }else if(hour == 0){
          sb4.append( "12" ).append( ":" ).append(minute).append( "AM" );
        }else{
          sb4.append(hour).append( ":" ).append(minute).append(" AM");
        }


        alternative.setText( "Alternative times: " + sb3 + " (9 hours)" + sb4 + " (6 hours)" );

Please help me figure out how to display 12 instead of 0 when the calculated time is 12:00 midnight. Thanks!

© Stack Overflow or respective owner

Related posts about android

Related posts about date