import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class date {
public static void main (String args[]) throws ParseException
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date expiry = sdf.parse("2012-11-09");
Date today1 = new Date();
String dt = sdf.format(today1);
Date today = sdf.parse(dt);
System.out.println(today);
System.out.println(sdf.format(expiry));
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(expiry);
cal1.add(Calendar.DATE, -2);
cal2.setTime(today);
System.out.println(cal1.getTime());
System.out.println(cal2.getTime());
int j = cal2.compareTo(cal1);
System.out.println("The result is :" + j);
}
}
0 comments:
Post a Comment