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.
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); } }
Current date = Mon Nov 19 05:32:19 UTC 2018 Milliseconds = 1542605539301