Home »
Java Programs »
Core Java Example Programs
Java program to get elapsed time in seconds and milliseconds
This program will calculate elapsed time by a java program in seconds and milliseconds.
Get elapsed time by a program in Java
//Java program to get elapsed time in seconds and milliseconds.
import java.util.Scanner;
public class ElapsedTime
{
public static void main(String[] args)
{
long startTime; //start time
long endTime; //end time
double time; //time difference
startTime = System.currentTimeMillis();
//doing some operation
//read and print your name
System.out.print("Enter you name: ");
//Scanner class object
Scanner SC=new Scanner(System.in);
String name=SC.nextLine();
System.out.println("Thanks "+ name +" ! ");
endTime = System.currentTimeMillis();
time = (endTime - startTime) / 1000.0;
System.out.println("\nElapsed Time is: " + time);
}
}
Output
Enter you name: Alexender
Thanks Alexender !
Elapsed Time is: 3.452
Core Java Example Programs »