create a date class in java having day, month and year data members. create constructor for initializing data members, functions for validating date, getting values of data members and displaying the date?
Answers
Explanation:
The class Date represents a specific instant in time, with millisecond precision. The Date class of java.util package implements Serializable, Cloneable and Comparable interface. It provides constructors and methods to deal with date and time with java.
Constructors
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)
Date(int year, int month, int date, int hrs, int min, int sec)
Date(String s)
Note : The last 4 constructors of the Date class are Deprecated.
// Java program to demonstrate constuctors of Date
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Date d1 = new Date();
System.out.println("Current date is " + d1);
Date d2 = new Date(2323223232L);
System.out.println("Date represented is "+ d2 );
}
}
please make me as brainlist and follow me bro and thanks me