Question: Using JAVA I'm trying to display the current time but it says theres an error if some one could look at this and show me
Using JAVA
I'm trying to display the current time but it says theres an error if some one could look at this and show me where I'm going wrong
// Written by: Will Van Velsor // Date 1/26/2020
public class ShowCurrentTime { public static void main(String[] args) { // Obtain the total milliseconda since midnight, Jan 1, 1970 long totalMilliseconds = System.currentTimeMillis(); // Obtain the total seconds since midnight, Jan 1, 1970 long seconds = totalTimeMilliseconds / 1000; //compute the current second in minute in the hour long currentSecond = totalSeconds % 60; // obtain the total minutes long totalMinutes = totalSeconds / 60; // 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 "; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
