Java Date() Constructor

Syntax

Date() constructor from Date has the following syntax.

public Date()

Example

In the following code shows how to use Date.Date() constructor.


import java.util.Date;
/*  w  ww.  j a  v  a2s  . com*/
public class Main{
  public static void main(String args[]) {
    Date date = new Date();

    System.out.println(date);

    long msec = date.getTime();
    System.out.println("Milliseconds since Jan. 1, 1970 GMT=" + msec);
  }
}

The output: