Home Java Java-conversion Convert Date to Milliseconds



Convert Date to Milliseconds
Posted on: June 14, 2007 at 12:00 AM
In this section, you will learn how to convert date into milliseconds in Java.

Convert Date to Milliseconds

     

In this section, you will learn to convert a date into milliseconds. A millisecond is one thousand part of a second i.e. an unit for measuring the time. 

Description of program:

This example helps you in converting a date into milliseconds. The Date() constructor represents the current date (time) in GMT (Greenwich Mean Time) format. Here we use the getTime() method. This method converts the date into milliseconds as long type.

 

 Here is the code program:

import java.util.*;
import java.text.*;
import java.sql.Timestamp;
public class DateToMilliseconds {
 public static void main(String[] args) {
 Date date=new Date() ;  
 System.out.println("Today is " +date.getTime());
  
}    

Output of program:

C:\date>javac DateToMilliseconds.java
C:\date>java DateToMilliseconds
Today is 1181644914093

Download this example.

Related Tags for Convert Date to Milliseconds:
cdatetimeconvertmethodgettypereturnintthisexamplelongtoexameilitliusepeiminconvertingasmmillisecondsntesmillisecondmeintoxaxampsurnatisimellmplgettimearrtsecondsusesttssthcondpleplmindono


More Tutorials from this section

Ask Questions?    Discuss: Convert Date to 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.