Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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?


  #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).

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

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