im designing a 12 hour clock, converting it from a 24 hour clock. i had the idea of keeping the clock internally as 24 hours, and externally showing it as a 12 hour clock. The code I have is
public String getTime()
{
if (hours.getValue() >12)
{
hours.setValue(hours.getValue() - 12);
System.out.println(hours.getDisplayValue() + ":"+ minutes.getDisplayValue() +"pm");
}
else
{
System.out.println (hours.getDisplayValue() + ":"+ minutes.getDisplayValue() + "am");
}
if(hours.getValue() == 0)
{
System.out.println("12"+":"+ minutes.getDisplayValue() + "am");
}
return hours.getDisplayValue() + ":"+ minutes.getDisplayValue();
}
It works fine until I use the function of tick which increases the minutes by 1. because of the maths i have in the code hours - 12 the hours become under 12, and so it prints the time after as AM. So for example I create the time 13:00 it shows as 1:00pm then i use the tick method it changes to 1:01 am. I would be extremely grateful if someone could help me sort out my code. Thank you for your time