This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

awkward date string  RSS feed

 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I 've got bitten by the following fixed format date string when parsing it (into a Joda DateTime) :

Feb 9 2007
Feb 12 2007

I can't find a pattern that can handle the days correctly.
Any other clean solution except for checking the fifth character (space or not) and then use either "MMM d yyyy" or "MMM d yyyy" as pattern?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How exactly are you trying to parse the date string? I wrote the following simple example and it works without problems. (Not using Joda time, just the JDK classes).

Output:

Fri Feb 09 00:00:00 CET 2007
Mon Feb 12 00:00:00 CET 2007
[ February 13, 2007: Message edited by: Jesper Young ]
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, formatting got screwed up

It is about the 2 spaces between Feb and 9 and only one between Feb and 12. This results in fixed length strings but with a space instead of '09'.

My current method looks like:


[ February 13, 2007: Message edited by: bart zagers ]
[ February 13, 2007: Message edited by: bart zagers ]
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, but my test program still works the same if I add an extra space:

Output is still:

Fri Feb 09 00:00:00 CET 2007
Mon Feb 12 00:00:00 CET 2007

Did you try it out? Do you get an exception if you try this?

I'm running my test program on Java SE 6. What version are you using?
[ February 14, 2007: Message edited by: Jesper Young ]
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

You are right, it works using the SimpleDateFormat.
I only tried it using Joda's DateTimeFormatter and there it (still) fails. I assumed they had the same behaviour, but didn't check.
I'll take this to the Joda mailing list.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!