Java Program to display date and time in Milliseconds

Java 8Object Oriented ProgrammingProgramming

Firstly, to display date and time, import the following package.

import java.util.Date;

Display the current date using Date class.

Date currentDate = new Date();

Let us now get milliseconds since Jan. 1, 1970 GMT

long res = currentDate.getTime();

The following is an example.

Example

 Live Demo

import java.util.Date;
public class Example {
   public static void main(String args[]) {
      Date currentDate = new Date();
      System.out.println("Current date = "+currentDate);
      // getting milliseconds since Jan. 1, 1970 GMT
      long res = currentDate.getTime();
      System.out.println("Milliseconds = " + res);
   }
}

Output

Current date = Mon Nov 19 05:32:19 UTC 2018
Milliseconds = 1542605539301
raja
Published on 17-Dec-2018 09:43:58
Advertisements