Java DateFormat equals() Example
DateFormat class equals() method example. This example shows you how to use equals() method.
Syntax is : public boolean equals(Object obj)
This method checks that specified object is equal to this object or not.
Here is the code.
/**
* @(#) EqualsDateFormat.java
* A class representing use of method equals() of DateFormat
class in java.text Package.
* @Version 12-May-2008
* @author Rose India Team
*/
import java.util.*;
import java.text.*;
class EqualsDateFormat {
public static void main(String[] args) {
// Create new Date object that will be initialized to the current date.
Date date = new Date();
System.out.println("Date by Date class : " + date.toString());
// Create new DateFormat object that will returns default date/time.
DateFormat dateFormat = DateFormat.getInstance();
String stringDate = dateFormat.format(date);
System.out.println("Date by DateFormat class : " + stringDate);
// Create another instance in short style.
DateFormat d = dateFormat.getDateInstance(DateFormat.SHORT);
System.out.println("Date in SHORT style : " + d.format(date));
// equals method call.
boolean bool = dateFormat.equals(d);
System.out.println("Both objects are equal......." + bool);
}
} |
Output of the program.
Date by Date class : Fri Jun 13 18:20:32 GMT+05:30 2008
Date by DateFormat class : 6/13/08 6:20 PM
Date in SHORT style : 6/13/08
Both objects are equal.......false |
|