Verify if a date is after another one

Verify dates is something that many java starters have doubts. Often they get an own solution to the problem when there is no need.

See what the java.util.Date can do for us:

public void verifyDates(String strCompareDate)
{
    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");

    Date date = new Date();
    Date compareDate = null;

    try
    {
        compareDate = format.parse(strCompareDate);
    }
    catch (ParseException p){p.printStackTrace();}

    if(compareDate.after(date))
    {
        // do something
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s