Listing 2.7, ShowCurrentTime.java, gives a program that displays the current time in GMT. Revise the program so
Question:
Listing 2.7, 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:
Enter the time zone offset to GMT: ?5
The current time is 4:50:34
Transcribed Image Text:
1 public class ShowCurrentTime { 2 public static void main(String [] args) { // Obtain the total milliseconds since midnight, Jan 1, 1970 long totalMilliseconds = System.currentTimeMillis(); 3 // 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 totalMinutes 14 // Compute the current minute in the hour long currentMinute = totalMinutes % 60; 15 16 currentMinute 17 // Obtain the total hours long totalHours = totalMinutes / 60; 18 19 totalHours 20 // Compute the current hour long currentHour = totalHours % 24; 21 22 currentHour 23 // Display results System.out.println("Current t ime is " + currentHour + + currentMinute + ":" + currentSecond + " GMT"); 24 25 26 27 preparing output 28 }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (6 reviews)
Output 5Enter the time zone offset to GMT Current time is 8376 GMT The Java program takes offset to ...View the full answer
Answered By
Muhammad Umair
I have done job as Embedded System Engineer for just four months but after it i have decided to open my own lab and to work on projects that i can launch my own product in market. I work on different softwares like Proteus, Mikroc to program Embedded Systems. My basic work is on Embedded Systems. I have skills in Autocad, Proteus, C++, C programming and i love to share these skills to other to enhance my knowledge too.
3.50+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Listing 2.6, 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...
-
Revise Programming Exercise 2.8 to display the hour using a 12-hour clock. Here is a sample run: Listing 2.7, ShowCurrentTime.java, gives a program that displays the current time in GMT. Revise the...
-
Write a program that displays Welcome to Java five times.
-
After 1 0 0 0 B . C . E . trade in Greece allowed for the accumulation of wealth by Kings Aristoi Farmers Foreigners
-
Estimate the limit numerically or state that the limit does not exist. If infinite, state whether the one-sided limits are or - . 25. 27. x-4 (x-4)3 2 9 lim
-
Should project managers ever be allowed to serve on the governance committee of a project while they are acting as the project manager on another project?
-
Describe the scope of coverage under the medical payments coverage of the PAP, including the persons to whom the coverage is applicable
-
High-low method Ken Howard, financial analyst at KMW Corporation, is examining the behavior of quarterly maintenance costs for budgeting purposes. Howard collects the following data on machine-hours...
-
Marcel Company has the following projected costs for manufacturing and selling and administrative expenses: (Click the icon to view the projected costs.) Prepare a schedule of cash payments for...
-
1. Using the Big Five personality factors, describe Ellisons personality characteristics. How do these affect others? 2. Whats Ellison EQ? Why do individuals work for him? MINI CASE Larry Ellison,...
-
Write a program that prompts the user to enter the minutes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days. Here is a sample...
-
Average acceleration is defined as the change of velocity divided by the time taken to make the change, as shown in the following formula: Write a program that prompts the user to enter the starting...
-
Below your own activity list, make a list of the assumptions you are making. Once complete, share your list and listen to the lists of assumptions other students recorded. Are you surprised how many...
-
Listed below are the amounts (dollars) it costs for marriage proposal packages at different baseball stadiums. Find the range, variance, and standard deviation for the given sample data. Include...
-
The Lotto Case (Hitting the Jackpot) Allen B. Atkins, Roxanne Stell, & Larry Watkins Bob, Chad and Dylan had been dreaming of this day for the past six years; ever since they first met in an...
-
Boxplots. In Exercises 29-32, use the given data to construct a boxplot and identify the 5-number summary. Taxis Listed below are times (minutes) of a sample of taxi rides in New York City. The data...
-
Use the birth weights (grams) of the 400 babies listed in Data Set 6 "Births" in Appendix B. Examine the list of birth weights to make an observation about those numbers. How does that observation...
-
Listed below are annual U.S. sales of vinyl record albums (millions of units). The numbers of albums sold are listed in chronological order, and the last entry represents the most recent year. Do the...
-
Draw the shear and moment diagrams for the beam. 3 kN 6 kN/m B 1.5 m 1.5 m
-
What can you do to reduce hunger where you live? To reduce hunger globally?
-
Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown...
-
Write the bin2Dec(String binaryString) method to convert a binary string into a decimal number. Implement the bin- 2Dec method to throw a NumberFormatException if the string is not a binary string....
-
The bin packing problem is to pack the objects of various weights into containers. Assume each container can hold a maximum of 10 pounds. The program uses an algorithm that places an object into the...
-
Suppose a smoker indicates on an application for medical expense insurance that he is a nonsmoker. Is this misrepresented material?
-
Question 10. What is the effect of traders storing grain to wait for higher prices? 1. It is essential in preventing grain shortages. 2. Traders are able to monopolize the market. 3. Most shortages...
-
Differentiate between the profit and loss from writing a covered call option versus a naked call option
Study smarter with the SolutionInn App