andrewsw, on 27 February 2013 - 03:38 PM, said:
Well this works for me, using getTime()
but only if I use before() rather than equals(), because getTime() includes a time element.
If you need to use equals() instead then you'll need to remove the time element (or use another approach).
public void isTimeValid() {
Calendar dateTime = Calendar.getInstance();
Date currDate = dateTime.getTime();
String dateStr = "27/02/2013";
DateFormat formatter;
Date date;
formatter = new SimpleDateFormat("dd/MM/yyyy");
try {
date = (Date) ((DateFormat) formatter).parse(dateStr);
} catch (ParseException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
return;
}
if (date.before(currDate))
{
System.out.println("Card Is Valid");
} else
{
System.out.println("Card Not Valid");
}
}
but only if I use before() rather than equals(), because getTime() includes a time element.
If you need to use equals() instead then you'll need to remove the time element (or use another approach).
Ahh thanks this helps, how would I get it to check if its equals to todays date?

New Topic/Question
Reply




MultiQuote



|