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:
- Date(): It initializes the object with the current date and time.
- 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);
}
} |
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:
Please follow and like us: