Link to home
Create AccountLog 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
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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)