File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Calendar.getInstance.getTimeInMillis()  Vs  System.currentTimeMillis() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Calendar.getInstance.getTimeInMillis()  Vs  System.currentTimeMillis()" Watch "Calendar.getInstance.getTimeInMillis()  Vs  System.currentTimeMillis()" New topic
Author

Calendar.getInstance.getTimeInMillis() Vs System.currentTimeMillis()

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1303
Calendar.getInstance.getTimeInMillis() is similar to System.currentTimeMillis(). Both are giving long values. Which gives good performace than others. I am planning to use this for audit purpose.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 1808
    
    2
Most of use don't bother with micro optimization.

Why don't you create a simple program using each method in a loop and then report back on your findings.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16810
    
  19

Under the covers, the Calendar classes uses the System.currentTimeMillis() method call to create a Calendar class with the current time. If all you want is the current time in millis, it's probably better to call the System class directly.

But I agree with Rob. This is unlikely to make any difference, and you should only optimize if you first confirm that its an issue first.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Calendar.getInstance.getTimeInMillis() Vs System.currentTimeMillis()
 
Similar Threads
Java Performance Issue
Date problem
Time Computation
How to convert now date to Timestamp ??
check efficiency