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());
 
  }
 
}
Tags :
Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

Related Posts

Popular Posts