This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Another format check :P 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 » Beginning Java
Bookmark "Another format check :P" Watch "Another format check :P" New topic
Author

Another format check :P

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Hello,

I need to check a String if has the correct date format (DD/MM/YYYY).

I have created



but now i dont know how to compare my String with dateFormat to find if is valid. Also i have to check if DD is from 01-31 MM is from 01-12
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Is your requirement to check that the string represents an actual date? Or will you accept "31/02/2011" as valid?
Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Not the current date, just a date in that format
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Checking if a String represents a valid usually means parsing that String into a Date. There are several threads about that; I've posted in quite a few of these already.
And what Paul meant is disallowing invalid dates like February 31st. You can make the date format non-lenient to disallow this.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Another format check :P
 
Similar Threads
how to convert date to a string
Code review required for converting dateformat
Getting date as a string from util.date object in desired format format
how to change the date,Time format after accessing it from the database
date format