File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes combo question: date formats and general question about exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "combo question: date formats and general question about exceptions" Watch "combo question: date formats and general question about exceptions" New topic
Author

combo question: date formats and general question about exceptions

Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 82
Hi,
I'm writing a web app that uses dates, and in some cases I have the user enter dates in an html form and then I need to convert that input to a java date format...I usually use GregorianCalendar.

First...is that the best date format? Or is SimpleDateFormat better? I use GregorianCalendar mainly because the books and tutorials I came across when I was learning used it.

In my webapp stuff I'll usually have the user select values from a pulldown, and then have a method that converts it to a gregorianCalendar.

Which brings me to my 2nd question...

Does it make sense to write my own exception for an improper date? The method that converts the html form values to a calendar could then throw the exception, but is it considered overkill to put something that simple in a try/catch?

thanks!
bp
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

It's best not to ask "combo questions" as one or the other usually falls by the wayside. It can also make posts confusing for future searches.

If SimpleDateFormat works, it's probably less overhead and with a simpler API.

I never use exceptions for anything other than exceptional conditions, of which data validation is not (in my opinion).


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
 
subject: combo question: date formats and general question about exceptions
 
Similar Threads
Spring MVC : InitBinder for non form values.
Two drop-down list that used the same javascript function
Dates and Times confusion (again)
problems with SimpleDateFormat
Date Calculation in JAVA - Is it really trivial ?