Output

Variable Name     Value in Memory
totalMilliseconds
seconds
currentSecond
totalMinutes
currentMinute
totalHours
currentHour
  1  public class ShowCurrentTime {
  2    public static void main(String[] args) {
  3      // Obtain the total milliseconds since midnight, Jan 1, 1970
  4      long totalMilliseconds = System.currentTimeMillis();
  5  
  6      // Obtain the total seconds since midnight, Jan 1, 1970
  7      long totalSeconds = totalMilliseconds / 1000;
  8  
  9      // Compute the current second in the minute in the hour
 10      long currentSecond = totalSeconds % 60;
 11  
 12      // Obtain the total minutes
 13      long totalMinutes = totalSeconds / 60;
 14  
 15      // Compute the current minute in the hour
 16      long currentMinute = totalMinutes % 60;
 17  
 18      // Obtain the total hours
 19      long totalHours = totalMinutes / 60;
 20  
 21      // Compute the current hour
 22      long currentHour = totalHours % 24;
 23  
 24      // Display results
 25      System.out.println("Current time is " + currentHour + ":"
 26        + currentMinute + ":" + currentSecond + " GMT");
 27    }
 28  }