Problem

(Current time) Listing 1, ShowCurrentTime.java, gives a program that displays the current...

(Current time) Listing 1, ShowCurrentTime.java, gives a program that displays the current time in GMT. Revise the program so that it prompts the user to enter the time zone offset to GMT and displays the time in the specified time zone. Here is a sample run:

LISTING 1 ShowCurrentTime.java

1 public class ShowCurrentTime {

2      public static void main(String[] args) {

3           // Obtain the total milliseconds since midnight, Jan 1, 1970

4           long totalMilliseconds = System.currentTimeMillis();

5

6           // Obtain the total seconds since midnight, Jan 1, 1970

7           long totalSeconds = totalMilliseconds / 1000;

8

9           // Compute the current second in the minute in the hour

10         long currentSecond = totalSeconds % 60;

11

12         // Obtain the total minutes

13         long totalMinutes = totalSeconds / 60;

14

15         // Compute the current minute in the hour

16         long currentMinute = totalMinutes % 60;

17

18         // Obtain the total hours

19         long totalHours = totalMinutes / 60;

20

21         // Compute the current hour

22         long currentHour = totalHours % 24;

23

24         // Display results

25         System.out.println("Current time is " + currentHour + ":"

26         + currentMinute + ":" + currentSecond + " GMT");

27    }

28 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT