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: 60% (5 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
-
Find the missing side of each triangle. Round your answers to the nearest tenth if necessary. 9.6 cm 14.7 cm X
-
James Lewis, a resident of Kentucky, sustained an injury while operating a Caterpillar bulldozer. He filed suit against Caterpillar, a company incorporated in Delaware but with its principal place of...
-
Holz Disc Golf Course was opened on March 1 by Ian Holz. The following selected events and transactions occurred during March. Mar. 1 Invested $20,000 cash in the business. 3 Purchased Rainbow Golf...
-
Please share a quote from Dr. Thom Garfat's piece where he signals, implicitly or explicitly, how this relational model frames youths. Identify something the relational CYC/"inter-personal...
-
Calculate the heat required to raise 50 kg of solid sodium carbonate (Na2CO3) from 10C to 50C at 1atm using (a) The true heat capacity of Na2CO3, which is 1.14 kJ / (kg C). (b) A heat capacity...
-
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...
-
What are the potential benefits of a pegged currency system?
-
According to equity theory, what are the major considerations that couples take into account in evaluating their levels of satisfaction?
-
Consider the following code: int main() { } char names [4] [5] for (int i=0; i <4; i++) = { "Ant", "Bee", "Cat", "Duck"}; printf("%s ", names[i]); 1. Add another string to the array: kangaroo 2. Make...
-
1. The table below contains information about Company X and Company Y. Company Y 42 2 1.48 Current Market Value (million) Number of Shares (million) Earnings per share Company X 70 4 0.75 a)...
-
If f(x) = 6 + Find f'(4). Find f'(x). Find f"(4). 3 X 6 + 22, find f'(x).
-
For the network-of-queues with probabilistic routing given in Figure 19.3, sup- pose that that each server serves at an average rate of 10 jobs/sec; that is, p= 10, Vi. Suppose that r2 = r3= 1....
-
Refer to the information presented for E-Perform Ltd. in P17-7A. Additional information: 1. Accounts payable relate only to merchandise creditors. 2. Accrued expenses payable and prepaid expenses...
-
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...
-
1. What traits do you admire in leaders and professionals from your own experience? Why? 2. Identify your leadership strengths and weaknesses. How do you plan to address the areas that need...
-
1. Define a project system. 2. List and discuss five major functions in project planning. 3. Describe the role of the project manager in project planning. 4. Develop a project planning model for the...
-
John and Frank are in an automobile accident. John sues Frank for $100,000.00 in a comparative negligence state. John has been assigned 40% of the fault by the jury and Frank 60% of the fault by the...
Study smarter with the SolutionInn App