Solved
advancing 60 min to hour and 2 digit display
Posted on 2007-07-24
Hello everyone, I have a question and need some help with this. I know i need to create an If statement to look at the hours and minutes as well as het the am/pm working. I have a idea about how it should be done but am not clear how to approach it. How do we handle the time display to be 2 digits 00 I have included the current code and need some up with this part.
amPmDisplay.setText("am");
If (hr > 12){
ampmDisplay.setText("pm");
hr = 1 // do we handle the time display to be 2 digits 00
}
If (min > 59{
hr = hr + 1 //do we handle the time display to be 2 digits 00
min = 0 //do we handle the time display to be 2 digits 00
}
if (selected == HR)
{
String time = guiPanel.timeDisplay.getText();
String[] splitTime = time.split(":");
int hr = Integer.parseInt(splitTime[0].trim());
time = Integer.toString(hr + 1) + ":" + splitTime[1] + ":" + splitTime[2];
guiPanel.timeDisplay.setText(time); //modified time
}
else if (selected == MIN)
{
String time = guiPanel.timeDisplay.getText();
String[] splitTime = time.split(":");
int min = Integer.parseInt(splitTime[1].trim());
time = splitTime[0] + ":" + Integer.toString(min + 1) + ":" + splitTime[2];
guiPanel.timeDisplay.setText(time); //modified time
}
}
else if (cmd.equals(guiPanel.downButton.getText()))
{
if (selected == HR)
{
String time = guiPanel.timeDisplay.getText();
String[] splitTime = time.split(":");
int hr = Integer.parseInt(splitTime[0].trim());
time = Integer.toString(hr - 1) + ":" + splitTime[1] + ":" + splitTime[2];
guiPanel.timeDisplay.setText(time); //modified time
}
else if (selected == MIN)
{
String time = guiPanel.timeDisplay.getText();
String[] splitTime = time.split(":");
int min = Integer.parseInt(splitTime[1].trim());
time = splitTime[0] + ":" + Integer.toString(min - 1) + ":" + splitTime[2];
guiPanel.timeDisplay.setText(time); //modified time
}
}