- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Computer elapsed time of an operation in milliseconds in Java
To compute the elapsed time of an operation in milliseconds in Java, we use the System.currentTimeMillis() method. The java.lang.System.currentTimeMillis() returns the current time in milliseconds.
Declaration −The java.lang.System.currentTimeMillis() is declared as follows −
public static long currentTimeMillis()
The method returns time difference in milliseconds between the current time and midnight, January 1, 1970 (UTC or epoch time).
Let us see a program to compute the elapsed time of an operation in milliseconds in Java −
Example
public class Example { public static void main(String[] args) throws Exception { // finding the time before the operation is executed long start = System.currentTimeMillis(); for (int i = 0; i <5; i++) { Thread.sleep(60); } // finding the time after the operation is executed long end = System.currentTimeMillis(); // finding the time difference float msec = end - start; System.out.println(msec + " milliseconds"); } }
Output
301.0 milliseconds
- Related Articles
- Compute the elapsed time of an operation in Java
- Java Program to display computer time in milliseconds
- Get elapsed time in Java
- Measuring elapsed time in Java
- Compute elapsed time in seconds in Java
- Get elapsed time in minutes in Java
- Compute elapsed time in hours in Java
- Get elapsed time in days in Java
- How to measure elapsed time in Java?
- How to calculate elapsed/execution time in Java?
- Get time in milliseconds using Java Calendar
- How to measure elapsed time in nanoseconds with Java?
- Display entire date time with milliseconds in Java
- Java Program to display date and time in Milliseconds
- Finding the time elapsed in JavaScript

Advertisements