How to get time in milliseconds in Java
Published: January 29, 2009 , Updated: January 20, 2009 , Author: mkyong
In Java, there’s two methods to get time in milliseconds
1) Date class – getTime() method
2) Calendar class – getTimeInMillis() method
import java.util.Calendar; import java.util.Date; public class TimeMilisecond { public static void main(String[] argv) { long lDateTime = new Date().getTime(); System.out.println("Date() - Time in milliseconds: " + lDateTime); Calendar lCDateTime = Calendar.getInstance(); System.out.println("Calender - Time in milliseconds :" + lCDateTime.getTimeInMillis()); } }







There is a third option and you avoid the cost of create a new object. Using the static method of class System:
– System.currentTimeMillis();
Even if u want nanoseconds precision u can use:
– System.nanoTime();
hi your idea is great !!! thanks for sharing it
There is a third option and you avoid the cost of create a new object. Using the static method of class System: