ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.