我想知道我下面的代码有什么问题:
// 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)" );
请帮我弄清楚当计算的时间是午夜 12:00 时如何显示 12 而不是 0。谢谢!