This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Parsing dates with dashes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parsing dates with dashes" Watch "Parsing dates with dashes" New topic
Author

Parsing dates with dashes

Tarek Nabil
Greenhorn

Joined: May 07, 2005
Posts: 1
Hi everyone,

This might sound like a trivial problem, I personally never thought I would have a problem parsing dates, but it seems like the SimpleDateFormat class does not like dashes.

SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
System.out.println(format.parse("24-09-1976"));

java.text.ParseException: Unparseable date: "24-09-1976"

at java.text.DateFormat.parse(DateFormat.java:319)

at test.TestMisc.testDateParse(TestMisc.java:12)

at test.TestMisc.main(TestMisc.java:21)

Please help.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i found no prob whatsoever:

Fri Sep 24 00:00:00 BST 1976


java amateur
Annie Smith
Ranch Hand

Joined: Mar 05, 2005
Posts: 172
Even I didn't find any problem when I replied to the same question on Sun's forum. Maybe there is some older class file creating the problem.


Cheers!<br /><b>Annie</b>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing dates with dashes
 
Similar Threads
convert a String to a Date
Date Validation
problem with dates
Saving system date
Date Formatting