Can some one please take a look, adn let me know what I am doing wrong?
please take a look at the complete code in question...
public class DateStamp {
public DateStamp() {
}
public static void main(String[] args) {
DateStamp ds = new DateStamp();
String s ="2001-07-20".trim();
ds.setThisDate(s);
}
public void setThisDate(String s) {
s = s.trim();
DateFormat df =new SimpleDateFormat("yyyy-MM-dd");
Date requiredDate=null;
Date currentDate=null;
try{
requiredDate = df.parse(s);//results here are as desired
currentDate = df.parse(getCurrentDate());//current date is one month short
}catch(ParseException pe) {
pe.printStackTrace();
}
System.err.println("below is the comparison\n");
System.err.println("Current date is ["+currentDate+"]");
System.err.println("date to be compared is["+requiredDate+"]");
System.err.println("Comparison result ["+requiredDate.compareTo(currentDate));
}
/**
* @returnCurrent time and date
*/
public String getCurrentDate() {
String currentdate = new String();
Calendar calender = new GregorianCalendar();
calender = Calendar.getInstance();
currentdate = calender.get(Calendar.YEAR) + "-" +
calender.get (Calendar.MONTH) + "-" +
calender.get(Calendar.DAY_OF_MONTH) ;
return currentdate;
}
here is the output for this program...
below is the comparison
Current date is [Wed Jun 20 00:00:00 MDT 2001]//this is my problem.it should be Fri July 20,but its not..please help some one...
date to be compared is[Fri Jul 20 00:00:00 MDT 2001]
Comparison result [1]

