Question: Listing 2.7, ShowCurrentTime.java, displays the current time. Improve this example to display the current date and time. The calendar example in Listing 6.12, PrintCalendar.java, should
Listing 2.7, ShowCurrentTime.java, displays the current time. Improve this example to display the current date and time. The calendar example in Listing 6.12, PrintCalendar.java, should give you some ideas on how to find the year, month, and day.
Listing 1
![1 public class ShowCurrentTime { public static void main(String[] args) { //](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2022/11/636a724a3bffb_458636a724a2b341.jpg)

Listing 2



1 public class ShowCurrentTime { public static void main(String[] args) { // Obtain the total milliseconds since midnight, Jan 1, 1970 long totalMilliseconds = System.currentTimeMillis(); 2 3 4 // Obtain the total seconds since midnight, Jan 1, 1970 long totalSeconds = totalMilliseconds / 1000; // Compute the current second in the minute in the hour long currentSecond = totalSeconds % 60; 10 11 // Obtain the total minutes long totalMinutes = totalSeconds / 60; 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 // Compute the current minute in the hour long currentMinute = totalMinutes % 60; // Obtain the total hours long totalHours - totalMinutes / 60; // Compute the current hour long currentHour - totalHours % 24; // Display results System.out.println("Current time is " + currentHour + + currentMinute + ":" + currentSecond + " GMT"); 28 } Current time is 17:31:8 GMT N~~6 N~~~
Step by Step Solution
3.50 Rating (157 Votes )
There are 3 Steps involved in it
Output Current date and time is 732011 5482 GMT Java program to display c... View full answer
Get step-by-step solutions from verified subject matter experts
