Link to home
Start Free TrialLog in
Avatar of mcgettiu
mcgettiu

asked on

Validating a date object

Hey guys....

Quick question...is it possible to validate a date object?
So i could throw an exception if date is set to something like 31 Feb 2007???

Thanks a mill
Una
Avatar of Ajay-Singh
Ajay-Singh

Try using SimpleDateFormat:

DateFormat format = new SimpleDateFormat("dd MMM yyyy);
format.parse("31 Feb 2007"); // Will throw an exception
Hi mcgettiu,

You can use the isValid() method on the DateTime object.

Regards
  Kelvin
ASKER CERTIFIED SOLUTION
Avatar of Ajay-Singh
Ajay-Singh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mcgettiu

ASKER

Ajay-Singh
I already have my date object...so do i have to covert this back to a string to the parse method from DateFormat?

KelvinY
What is the DateTime object?  I cant find it in the Java API?????
> I already have my date object
what do you mean? You have a date object that represents 31 Feb 2007
Avatar of CEHJ
>>I already have my date object...so do i have to covert this back to a string to the parse method from DateFormat?

Yes (although i don't know how you got the Date in the first place)