java util date class

java.util.Date

The Date class is available in java.util package. It represents a specific instant in time with millisecond precision.

Date class supports following two constructors:

  1. Date(): It initializes the object with the current date and time.
  2. Date(long millisec): initializes the object with the specified number of milliseconds since January 1, 1970, 00:00:00 GMT.

Java Date Class Methods

package com.w3spoint;
 
import java.text.SimpleDateFormat;
import java.util.Date;
 
public class GetDateTime {
	public static void main(String args[]){
		SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
		String date = sdf.format(new Date()); 
		System.out.println(date);
	}
}

Output:

09-04-2018
Please follow and like us:
Content Protection by DMCA.com