The date mentioned here refers to the date format of the string, such as "2014-10-15", we want to determine whether this date before today, the Internet to see a lot of judgments on the way, is to take this date into a Date object and then compare with the new date (), using Comparetto () or before () method, in fact, this will be a little bit of a problem, so ignore the one-hour minute comparison, there will be errors, not the correct results.
If you want to get the correct results, you should convert the current time new date () to the format "YYYY-MM-DD", and then judge the two by converting them to date, the code is as follows:
Java.util.Date nowdate = new Java.util.Date (); String date = Dateutils.formatdate (Nowdate, "yyyy-mm-dd"); SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd", Locale.china);D ate d;try {d = sdf.parse (dateformat); int flag = d . CompareTo (dateutils.formatdatefromestring (date)), if (flag >= 0) {//the same day and after the day, <0 is before the date}} catch (ParseException E {//TODO auto-generated catch Blocke.printstacktrace ();}
java--determine if the date is before today