Home Java Javadate Getting time in Milliseconds



Getting time in Milliseconds
Posted on: October 11, 2008 at 12:00 AM
In the previous examples of Date class we have created simple Date and now in this section we are going to get the current date and time in the milliseconds. To do this we have used getTime() method of Date class.

Getting time in Milliseconds

     

In the previous examples of Date class we have created simple Date and now in this section we are going to get the current date and time in the milliseconds. To do this we have used getTime() method of Date class.

getTime() returns the total time in milliseconds since 1 January 1970 00:00:00 GMT. getTime() returns total time in long datatype.

Here is the full example code of GetTimeMilliseconds.java as follows:

GetTimeMilliseconds.java

import java.util.Date;

public class GetTimeMilliseconds{

  public static void main(String[] args) {
     // Create a new instance of Date
       Date newDate = new Date();
       System.out.println("New Date:="+newDate);
     // getTime() method returns number of milliseconds since Jan 1970
        System.out.println("Number of milliseconds ==>"+newDate.getTime());
  }
} 

Compile this example with the javac command and execute it.

Output: 

C:\DateExample>javac GetTimeMilliseconds.java

C:\DateExample>java GetTimeMilliseconds
New Date:=Fri Oct 10 13:26:49 GMT+05:30 2008
Number of milliseconds ==>1223625409171

Download Source Code

Related Tags for Getting time in Milliseconds:
cclassdatetimeiomethodsedgetexamplesvithissimplecreateexampletoexameilsectionliuseimcurrentinnoasmmillisecondsntclesmillisecondmedoxaxampscreatedatishaimellmplpregogettimeeaandarsecondssimttssrenthcondavpleplprmindono


More Tutorials from this section

Ask Questions?    Discuss: Getting time in Milliseconds  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.