Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help in converting date from string

 
Alessandro Camel
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I try to convert a String into milliseconds but it seems that I am using the wrong pattern.




I'm still getting the same ParseException
 
Stephan van Hulst
Bartender
Pie
Posts: 5553
53
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is probably that the default locale can't make sense of "Mon". You can try constructing your format with Locale.ENGLISH.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always see at what index of the String the exception occurs by checking the ParseException's error offset:
In this case it fails because German expect "Mo", not "Mon". My default locale has no problems at all.
 
Alessandro Camel
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:The problem is probably that the default locale can't make sense of "Mon". You can try constructing your format with Locale.ENGLISH.


You are right!
Using :



everything is working!

Thanks!
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The German for Monday is Montag, so maybe the problem is Dec, which would be Dez for Dezember in German
 
Stephan van Hulst
Bartender
Pie
Posts: 5553
53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, but I think Alessandro is using Portuguese :P
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could have sworn somebody was using German. Oh yes, it’s Rob. That got me totally confused. Sorry.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was the first supported (as in: it is a static field of Locale), non-English locale I could think of
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic