logo image

Java program to show current time in seconds

Following program shows you how to print current time in seconds. We can get current milliseconds using System.currentTimeMillis() in java. Once we get those we need to divide with 1000 so that we get in seconds. In following program we are storing milliseconds in currentTimeInMilliSeconds variable and seconds in currentTimeInSeconds variable.

public class Basic17 {

	public static void main(String[] args) {

		long currentTimeInMilliSeconds = System.currentTimeMillis();
		long currentTimeInSeconds = currentTimeInMilliSeconds / 1000;

		System.out.println("Current time in seconds: " + currentTimeInSeconds);



Current time in seconds: 1521735884