Java System.currentTimeMillis()

Jakob Jenkov
Last update: 2014-06-23

The static method System.currentTimeMillis() returns the time since January 1st 1970 in milliseconds. The value returned is a long. Here is an example:

long timeNow = System.currentTimeMillis();

That is really all there is to it. The returned long value can be used to initialize java.util.Date, java.sql.Date, java.sql.Timestamp and java.util.GregorianCalendar objects.

Time Granularity

The granularity of the System.currentTimeMillis() method is larger than 1 millisecond. If you call this method repeatedly, you will see that you get the same value back for a while, then it all of a sudden jumps by 10-20-30 milliseconds or more. It is not the worlds most precise or fine grained timer.

Jakob Jenkov

Featured Videos

Java ForkJoinPool

P2P Networks Introduction


Java Persistence
Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Next tutorial in this tutorial trail