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.


The following is an 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());


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

Updated on: 27-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started