Date() : Creates date object representing current date and time.Date(long milliseconds) : Creates a date object for the given milliseconds since January 1, 1970, 00:00:00 GMT.Date(int year, int month, int date)Date(int year, int month, int date, int hrs, int min)
How do you create a Date in Java?
- import java.text.SimpleDateFormat;
- import java.util.Date;
- public class SimpleDateFormatExample {
- public static void main(String[] args) {
- Date date = new Date();
- SimpleDateFormat formatter = new SimpleDateFormat(“dd/MM/yyyy”);
- String strDate= formatter.format(date);
- System.out.println(strDate);
How are dates written in Java?
The DateFormat class in Java is used for formatting dates. A specified date can be formatted into the Data/Time string. For example, a date can be formatted into: mm/dd/yyyy.