Validate that a String is a particular date format

This is a discussion on Validate that a String is a particular date format within the Java forums in Programming Languages category; Hi, I'm using Java 1.5. How do I check if a string is a valid date in the format of "YYYY-MM-DD"? Note that this string "2008-02-31" is not a valid date. Thanks for your help, - Dave...

Go Back   Application Development Forum > Programming Languages > Java

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-27-2008, 03:44 PM
laredotornado
Guest
 
Default Validate that a String is a particular date format

Hi,

I'm using Java 1.5. How do I check if a string is a valid date in the
format of "YYYY-MM-DD"? Note that this string "2008-02-31" is not a
valid date.

Thanks for your help, - Dave
Reply With Quote
  #2  
Old 08-27-2008, 03:57 PM
Martin Gregorie
Guest
 
Default Re: Validate that a String is a particular date format

On Wed, 27 Aug 2008 12:44:04 -0700, laredotornado wrote:

> I'm using Java 1.5. How do I check if a string is a valid date in the
> format of "YYYY-MM-DD"? Note that this string "2008-02-31" is not a
> valid date.
>


SimpleDateFormat.parse()


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Reply With Quote
  #3  
Old 08-27-2008, 04:33 PM
Eric Sosman
Guest
 
Default Re: Validate that a String is a particular date format

Martin Gregorie wrote:
> On Wed, 27 Aug 2008 12:44:04 -0700, laredotornado wrote:
>
>> I'm using Java 1.5. How do I check if a string is a valid date in the
>> format of "YYYY-MM-DD"? Note that this string "2008-02-31" is not a
>> valid date.
>>

>
> SimpleDateFormat.parse()


.... and see also DateFormat.setLenient()

--
Eric.Sosman@sun.com
Reply With Quote
  #4  
Old 08-27-2008, 10:45 PM
Roedy Green
Guest
 
Default Re: Validate that a String is a particular date format

On Wed, 27 Aug 2008 12:44:04 -0700 (PDT), laredotornado
<laredotornado@zipmail.com> wrote, quoted or indirectly quoted someone
who said :

>I'm using Java 1.5. How do I check if a string is a valid date in the
>format of "YYYY-MM-DD"? Note that this string "2008-02-31" is not a
>valid date.


See http://mindprod.com/jgloss/calendar.html

See parse.
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 12:07 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.