Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 10th, 2003, 07:27 AM
Registered User
Join Date: Jun 2003
Location: Nazeing, Waltam Abbey, United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dates


I am using SimpleDateFormat to try and validate a date.
I am using the format MM/yy i.e. 05/02 the following:

            try {
                SimpleDateFormat sdf = new SimpleDateFormat("MM/yy");
            } catch (Exception e) {
                System.err.println("Date Format error");

 validates the presence of "/" in the date but doesn't validate the date ranges! How can i get SimpleDateFormat to validate the date ranges in this format. If I can't use this class do I have another option?


Reply With Quote
  #2 (permalink)  
Old June 27th, 2003, 05:43 AM
Authorized User
Join Date: Jun 2003
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to jwenting Send a message via MSN to jwenting

actually you can do it quite easily. java.text.DateFormat.parse(String source) will throw a java.text.ParseException if the string cannot be parsed into a valid java.util.Date Object (DateFormat is an ancestor of SimpleDateFormat).
Therefore, the Exception you're catching can have 2 meanings:
1) the string is not a valid date
2) the string is not a date at all
You'd have to add some more logic to determine which of the two is the case (like trying to create integers from the parts of the string that should contain numbers, if that fails you're into case 2).
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
dates again dhoward VB.NET 2002/2003 Basics 12 August 22nd, 2007 09:48 AM
dates DARSIN General .NET 4 January 14th, 2005 09:09 AM
dates in iis pab006 Classic ASP Basics 2 August 19th, 2004 01:08 AM
between dates capitala Access VBA 1 May 30th, 2004 05:20 PM
Dates treadmill SQL Language 3 July 3rd, 2003 02:32 PM

All times are GMT -4. The time now is 08:41 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.