VOOZH about

URL: https://www.geeksforgeeks.org/java/java-lang-system-currenttimemillis-method-with-examples/

⇱ Java.lang.System.currentTimeMillis() Method with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java.lang.System.currentTimeMillis() Method with Examples

Last Updated : 23 Jul, 2025

Before java 8 the compiler used to take it from the java.util package. But later since the use of date and time became important in every software and android application, java developed the date class after java 8. Date and time class via java.util package has been duplicated now. Java uses date and time class after the release of version java 8 to store the date and time. Now java usually stores Date in a typical fashion such that the number of milliseconds passed since 1 Jan 1970 in a long data type. Since it stores milliseconds the accuracy of the exact time increases.

The package view of the method is as follows:

--> java.lang Package
 --> System Class
 --> currentTimeMillis() Method  

Syntax: Getting milliseconds

System.currentTimeMillis();

Note: This return the number of milliseconds passed since 1970 as 00:00 1 January 1970 is considered as epoch time. Similarly, we can find out years, months, hours and rest of data from milliseconds.

(System.currentTimeMillis()) / 1000)                           Returns Seconds passed

(System.currentTimeMillis()) / 1000 / 60)                      Returns Minutes passed

(System.currentTimeMillis()) / 1000 / 60 / 60);                Returns Hours passed

(System.currentTimeMillis()) / 1000 / 60 / 60 / 24);           Returns days passed

(System.currentTimeMillis()) / 1000 / 60 / 60 / 24 / 365);     Returns Years passed

Example 1: Here all outputs are obtained from the epoch time set which is 1 January 1970. We can easily find seconds now if we divide the millisecond by 1000 we will get the number of seconds passed since 1 Jan 1970. 


Output
Milliseconds : 1655351172200
Seconds : 1655351172
Minutes : 27589186
Hours : 459819
Days : 19159
Years : 52

Example 2:


Output
Timing a loop from 0 to 100,000,000
Elapsed time: 83
Comment