11:00 pm - Thursday February 23, 2017

Date in java example program for compareTo(Date anotherDate)

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 program for compareTo(Dateanother Date)
 **/

import java.util.Date;

public class Compare {
	public static void main(String[] args) {
		// create two dates
		Date date = new Date(86, 7, 16);
		Date date2 = new Date(76, 9, 15);
		// make 3 comparisons with them
		int comparison = date.compareTo(date2);
		int comparison2 = date2.compareTo(date);
		int comparison3 = date.compareTo(date);
		// print the results
		System.out.println("Comparison Result:" + comparison);
		System.out.println("Comparison2 Result:" + comparison2);
		System.out.println("Comparison3 Result:" + comparison3);
	}
}

Output

Comparison Result:1
Comparison Result:-1
Comparison Result:0

BACK

Filed in: Z-A All Java Codes

Comments are closed.