3:11 pm - Wednesday November 25, 8820

Date in java example program for compareTo(Object o)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
 *@author: Candidjava
 *@description: Date in java example for compateTo(Object o)
 */
import java.util.Date;

public class Compare1 {
	public static void main(String[] args) {
		Date d1 = new Date();
		try {
			Thread.sleep(10);
		} catch (Exception e) {
			System.out.println("E");
		}
		Date d2 = new Date();
		System.out.println("First Date : " + d1.toString());
		System.out.println("Second Date : " + d2.toString());
		int results = d1.compareTo(d2);
		if (results > 0)
			System.out.println("First Date is after second");
		else if (results < 0)
			System.out.println("First Date is before second");
		else
			System.out.println("Both dates are equal");
	}
}

Output:

First Date : Thu Oct 11 13:48:14 IST 2012
Second Date : Thu Oct 11 13:48:14 IST 2012
First Date is before second

BACK

Filed in: Z-A All Java Codes

Comments are closed.