package com.mycompany.currenttime; public class Currenttime { public static void main(String[] args) { //4. Write a program that will tell the current time. // Hint use System.currentTimemillis() to get the total number of seconds long currentTimemillis = System.currentTimeMillis(); long totalseconds = currentTimemillis / 1000; long secondsnow = totalseconds % 60; long totalminutes = totalseconds / 60; long minutesnow = totalminutes % 60; long totalhours = totalminutes / 60; long hoursnow = totalhours % 24; System.out.println("The current time is: " + hoursnow + ":" +minutesnow + ":" + secondsnow ); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter