• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple Date Format problem

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am using the Simple Date format java class to format a date. I dont get any exception as the format of the date I am entering is correct. But if I enter a date like "23/23/2001" where the date format defined is "dd/MM/yyyy" the date is parsed successfully as 23 Nov 2001. But i want that some exception or errors should be thrown as the month is out of range.

Can anyone tell me how do i go about it?

Regards,
Suhas
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Call setLenient(false) on the DateFormat object. By default, Calendar and DateFormat objects are lenient, meaning they will overflow when an invalid date is encountered. If the leniency is set to false an IllegalArgumentException is thrown instead.
 
Suhas Bilaye
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,
Thanks a lot.
I forgot to mention that the SimpleDateFormat class is not of the java.text package but it is of the org.gwtwidgets.client.util package. This class can be used on client side when coding is to be done using GWT (Google Web Toolkit). It compliments the SimpleDateFormat class of the java.text package but the problem is that this class does not have the setLenient(<boolean>) method in it.

Regards,
reply
    Bookmark Topic Watch Topic
  • New Topic