Why is today’s date shown as before date ?
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Test {
public static void main(String args[]) throws ParseException {
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
List currentObject = new ArrayList();
currentObject.add("2012-09-27");
Date ExpDate = dateFormat.parse((String) currentObject.get(0));
if (ExpDate.before(date)) {
System.out.println("true");
}
else {
System.out.println("false");
}
}
}
Any ideas?
will yield the time too, but this
will default to
00:00:00, as yourdateFormatexcludes the time thus causing the time-part to be set to0h.So it’s correct:
is earlier than