Home Java Javadate Getting time in Milliseconds
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Getting time in Milliseconds

Advertisement
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

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 11, 2008

Related Tutorials

Ask Questions?    Discuss: Getting time in Milliseconds  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com