Java Program to convert Date into milliseconds



Import the following package to work with Date class.

import java.util.Date;

No create a Date object.

Date d = new Date();

Let us convert the current date to milliseconds.

d.getTime()

The following is an example.

Example

 Live Demo

import java.util.Date;
public class Demo {
   public static void main(String[] args) {
      Date d = new Date();
      System.out.println("Date = " + d);
      System.out.println("Milliseconds since January 1, 1970, 00:00:00 GMT = " + d.getTime());
   }
}

Output

Date = Mon Nov 19 06:30:11 UTC 2018
Milliseconds since January 1, 1970, 00:00:00 GMT = 1542609011369
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements