我想知道下面的代码有什么问题:
// 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。谢谢!
答案 0 :(得分:2)
hour = c.get( Calendar.HOUR );
minute = c.get( Calendar.MINUTE );
hour = c.get( Calendar.HOUR_OF_DAY );
您已经设置了hour
后再次设置。
答案 1 :(得分:-1)