.

Java Tutorial: Date and Time in Java

Date and Time

To operate on date cum time in java the classNameDate is existing it is employed to work on.

The classNamemaintains the list of constructors as below

  • date() to initialize present date and time
  • date (long millisec) it agrees number milliseconds since midnight

Date comparison;

In java using date classNamewe will compare the date in three ways.

  • Using getTime() method we can obtain number of milliseconds since midnight
  • Using before (), after (), and equals () method compare before any particular date or after or two date are equal.
  • Using compareTo() method we can compare two dates.

Example:

date-and-time-img1
.