- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Measuring elapsed time in Java
Sometimes, you may need to measure point in time in milliseconds. So let's re-write the above example once again −
Example
import java.util.*; public class DiffDemo { public static void main(String args[]) { try { long start = System.currentTimeMillis( ); System.out.println(new Date( ) + "
"); Thread.sleep(5*60*10); System.out.println(new Date( ) + "
"); long end = System.currentTimeMillis( ); long diff = end - start; System.out.println("Difference is : " + diff); } catch (Exception e) { System.out.println("Got an exception!"); } } }
This will produce the following result −
Output
Sun May 03 18:16:51 GMT 2009 Sun May 03 18:16:57 GMT 2009 Difference is : 5993
- Related Articles
- Get 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?
- Compute the elapsed time of an operation in Java
- How to measure elapsed time in nanoseconds with Java?
- Computer elapsed time of an operation in milliseconds in Java
- How to measure elapsed time in python?
- How to calculate Elapsed time in OpenCV using C++?
- Time Functions in Java
- Convert string of time to time object in Java
- Java Program to display Current Time in another Time Zone

Advertisements