Java.util.Date.equals() Method


Advertisements


Description

The java.util.Date.equals(Object obj) method checks if two Dates are equal,based on millisecond difference.

Declaration

Following is the declaration for java.util.Date.equals() method

public boolean equals(Object obj)

Parameters

obj − object to be compared with

Return Value

true if the objects are equal; false otherwise.

Exception

NA

Example

The following example shows the usage of java.util.Date.equals() method.

Live Demo
package com.tutorialspoint;

import java.util.*;

public class DateDemo {
   public static void main(String[] args) {

      // create 2 dates
      Date date = new Date(70, 1, 10);
      Date date2 = new Date(70, 1, 10);

      // Check if they are equal
      boolean check = date.equals(date2);

      // print the result
      System.out.println("Dates are equal:" + check);
   }
}

Let us compile and run the above program, this will produce the following result −

Dates are equal:true

java_util_date.htm

Advertisements
E-Books Store