troubleshooting Question

advancing 60 min to hour and 2 digit display

Avatar of Drop_of_Rain
Drop_of_Rain asked on
Java
38 Comments1 Solution347 ViewsLast Modified:
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
                                }
                        }
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 38 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 38 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros