Listing 2.7, ShowCurrentTime.java, displays the current time. Improve this example to display the current date and time.
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 give you some ideas on how to find the year, month, and day.
Listing 1
Listing 2
Transcribed Image Text:
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~~~
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 85% (7 reviews)
Output Current date and time is 732011 5482 GMT Java program to display c...View the full answer
Answered By
Shameen Tahir
The following are details of my Areas of Effectiveness. The following are details of my Areas of Effectiveness English Language Proficiency, Organization Behavior , consumer Behavior and Marketing, Communication, Applied Statistics, Research Methods , Cognitive & Affective Processes, Cognitive & Affective Processes, Data Analysis in Research, Human Resources Management ,Research Project,
Social Psychology, Personality Psychology, Introduction to Applied Areas of Psychology,
Behavioral Neurosdence , Historical and Contemporary Issues in Psychology, Measurement in Psychology, experimental Psychology,
Business Ethics Business Ethics An introduction to business studies Organization & Management Legal Environment of Business Information Systems in Organizations Operations Management Global Business Policies Industrial Organization Business Strategy Information Management and Technology Company Structure and Organizational Management Accounting & Auditing Financial Accounting Managerial Accounting Accounting for strategy implementation Financial accounting Introduction to bookkeeping and accounting Marketing Marketing Management Professional Development Strategies Business Communications Business planning Commerce & Technology Human resource management General Management Conflict management Leadership Organizational Leadership Supply Chain Management Law Corporate Strategy Creative Writing Analytical Reading & Writing Other Expertise Risk Management Entrepreneurship Management science Organizational behavior Project management Financial Analysis, Research & Companies Valuation And any kind of Excel Queries.
4.70+
16+ Reviews
34+ 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
-
Design a class named Time. The class contains:??The data fields?hour,?minute, and?second?that represent a time.? A no-arg constructor that creates a Time object for the current time. (The values of...
-
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...
-
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...
-
Consider a symmetric oligopoly in which firms technologies satisfy assumption 5.1. Assume that firms get part of the tax revenues refunded, according to their market shares. The refund share is 0 A...
-
Use Algorithm 7 to schedule the largest number of talks in a lecture hall from a proposed set of talks, if the starting and ending times of the talks are 9:00 a.m. and 9:45 a.m.; 9:30 a.m. and 10:00...
-
Which of the functions listed is not attributed to proteins? a) Catalyze biochemical reactions b) Transport substances from one place to another c) Mediate muscle contraction d) None of the above...
-
According to the Supreme Court decision in Quill Corp. v. North Dakota, a state may not require a retailer with no physical presence in the state to collect and remit sales tax on sales made in the...
-
Jason Wu operates Exclusive Limousines, a fleet of 10 limousines used for weddings, proms, and business events in Washington, D. C. Wu charges customers a flat fee of $ 250 per car taken on contract...
-
A. Find the value of x. B. 1. 2. 61 = x ( mod 7) 71 = x ( mod 8) 3. 78 x 3 (mod 5) 4. 89 = (x+3)( mod 4) 1. What is the remainder when 2021 2021 2020? is divided by
-
Currently, the risk-free rate is 10 percent and the expected return on the market portfolio is 15 percent. Market analysts' return expectations for four stocks are listed here, together with each...
-
Write a method that converts milliseconds to hours, minutes, and seconds using the following header: public static String convertMillis(long millis) The method returns a string as...
-
Write a method that finds the number of occurrences of a specified character in a string using the following header: public static int count(String str, char a) For example, count("Welcome", 'e')...
-
(a) If light is incident at an angle from a medium of index n1 on a medium of index n2 so that the angle between the reflected ray and refracted ray is , show thatsin(A + B) = sin A cos B + cos A...
-
What is the difference between Cauchy's convergence criterion and the Weier- strass M-test for series of functions? [4] (b) Using the Weierstrass M-test, establish uniform convergence of the series...
-
What assurance is provided when the auditor completes a set of tasks requested by the client and reports factually on the results of that work?
-
What are the advantages and disadvantages of cooperative strategies . Explain
-
What would be the effect on the balance sheet and the income statement if the accountant failed to make the above adjusting entries? Income Statement Balance Sheet
-
Suppose R is the region bounded from above by the graph of f(x) = 9x - z and from below by the graph of g(z) = z over the interval [2, 5]. Find the center of mass of the region. Assume that the...
-
The following are the eight balance-related audit objectives, seven tests of details of balances for accounts receivable, and seven tests of controls or substantive tests of transactions for the...
-
Assume that a trial balance is prepared with an account balance of $21,360 listed as $21,630 and an account balance of $1,500 listed as $15,000. Identify the transposition and the slide.
-
The rules of a programming language constitute its ____________. a. Syntax b. Logic c. Format d. Objects
-
A ____________translates high-level language statements into machine code. a. Programmer b. Syntax detector c. Compiler d. Decipherer
-
Named computer memory locations are called ____________. a. Compilers b. Variables c. Addresses d. Appellations
-
1. Consider a firm whose stock price at the end of the year depends on the state of the economy (good or bad with equal probability) and the outcome of a lawsuit (win with probability 0.8 and lost...
-
9) Consider a square matrix A such that ATA. One learner told me that the following three vectors are the eigenvectors of this matrix A. --10-8-4 Is learner telling the truth? Yes No 2 Can't say...
-
A very well known furniture retailer frequently advertises "no money down and no interest until 2006!" You want to buy some furniture now, and have a bit of spare cash available. You go to the store...
Study smarter with the SolutionInn App