Question: Read the the Case Study: Displaying the Current Time and follow along with the explanations and code. When you finish writing the program to display
leht Time to return the current time. that displays the current time in GMT (Greenwic her Point You can wre system.currentTimelillis() to The problem is to develop a program that displays the curre Time) in the format hour:minute:second, such as 13:19 The current TimeM1111s method in the System seconds elapsed since the time midnight, January 1, 1970 time is known as the UNIX epoch. The epoch is the point year when the UNIX operating system was formally intro enwich Mean ustem class returns the current 1. 1970 GMT, as shown in Fig the point when time starts, and mally introduced. current time in milli in Figure 2.2. This Starts, and 1970 was Elapsed time Time UNIX epoch 01-01-1970 00:00:00 GMT Current time System.current TimeMillis() entTimeMill78 FIGURE 2.2 The System.currentTimeMillis() retur since the UNIX epoch. returns the number of milliseconds 1000 = 1203183068 seconds). You can use this method to obtain the current time, then ute the current second, mine ute, and hour as follows: milliseconds since midnight, January 1, 1970, in totalMilliseconds 1. Obtain the total milliseconds since midnight, Januar current TimeMillis by invoking System. current TimeMillis() (e. (e.g., 1203183068328 milliseconds). 2. Obtain the total seconds totalSeconds by dividing to he total seconds total Seconds by dividing totalMilliseconds by 100 (e.g., 1203183068328 milliseconds / 1000 = 1203183068 Compute the current second from totaiseconds % 60 (e.g., 1203183068 seconds 60 = 8, which is the current second). otal minutes totalMinutes by dividing totalSeconds by 60 (e 1203183068 seconds / 60 = 20053051 minutes). 5. Compute the current minute from totalMinutes % 60 (eg 60 = 31, which is the current minute). 6. Obtain the total hours total Hours by dividing total Minutes by 60 (e.g., 2005 minutes / 60 = 334217 hours). 7. Compute the current hour from total Hours % 24 (e.g., 334217 hours % 24 which is the current hour)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
