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 parsing dates in a string Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "parsing dates in a string" Watch "parsing dates in a string" New topic
Author

parsing dates in a string

thomas silver
Ranch Hand

Joined: Jun 20, 2003
Posts: 32
Could someone show me the best way to parse the first occurrence of dates (could be in different date formats, MM/dd/yy, yyyy/MM/dd, etc.) in a string preferably without using regular expression? Thank you.
Raj S Kumar
Ranch Hand

Joined: Aug 06, 2006
Posts: 48
Hi Thomas,
Posting some sample strings would help us understand the problem better.


Raj S Kumar
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Use a List or array of DateFormats with the formats you will allow. Loop over them, use DateFormat.parse(String, ParsePosition) checking the return value against non-null.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
thomas silver
Ranch Hand

Joined: Jun 20, 2003
Posts: 32
Raj S Kumar wrote:Hi Thomas,
Posting some sample strings would help us understand the problem better.


Hi Raj,

It's just any text String with some form of date (in more than one possible formats) in it. The goal is to parse this date (in all possible formats) and print out the first occurrence. I hope I made myself clear. Thanks for reading.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Check my post.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35249
    
    7
Also see the JavaDatesFaq.


Android appsImageJ pluginsJava web charts
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: parsing dates in a string
 
Similar Threads
Java Dates
String[] : cut a Date every "/"
how to convert string to int in jsp?
how to parse string to date with defualt format?
java.text.ParseException