This is my code…
private void updateDisplay() {
if(hours.getValue() == 0){
hours.setValue(12);
displayString = hours.getDisplayValue() + ":" +
minutes.getDisplayValue() + " am";
}
else if(hours.getValue() < 12){
displayString = hours.getDisplayValue() + ":" +
minutes.getDisplayValue() + " am";
}
else if(hours.getValue() == 12){
displayString = hours.getDisplayValue() + ":" +
minutes.getDisplayValue() + " pm";
}
else if(hours.getValue() < 24){
displayString = hours.getValue() - 12 + ":" +
minutes.getDisplayValue() + " pm";
}
}
So basically this is a clock im trying to display in 12 hour format.. When it changes from 11:59pm
i get it to say 12:00 am but once I timeTick() it once it goes 12:01 pm because of my if hours.getValue == 0 then we make it 12 but later in the method its if hours.getValue() == 12 make it PM. I want to avoid that so. Any ideas on this while maintaining rather simple java?
RESOLVED Thank you. Instead of setValue(12) I just added 12 if hours.getValue() == 0
Why not just do what you do for when the hours equals 12?
Don’t actually set the hours value and just add 12 when you print it.