Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing locale specific Datetime String

 
Jammie Jamloki
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I parse locale specific date-time.

for example

"16 déc. 2012 08:55:55" -- please note :"déc"

Is there any generic way ?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't tried this but from a look at the DateFormat javadoc I would think using the setCalendar method to apply a Calendar with the required Locale might be worth trying.
 
Ishan Pandya
Ranch Hand
Posts: 226
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

try getDateInstance(int style, Locale aLocale) a method in DateFormat Class..

Hope this helps..
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch

You are quite a recent arrival if you have only waited 7 years for your first post.
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jammie Jamloki wrote:Is there any generic way ?

Well, in theory:should work; but I'm darned if I can get it working on my machine in Eclipse (it throws a ParseException).

It works just fine if I use Locale.UK and "16 dec. 2012 08:55:55" though, so I suspect it has something to do with either:
(a) the Locales that my machine/Eclipse supports, or
(b) the default character set that it's using.

If I get it working, I'll post my findings.

Winston
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot DateFormat was abstract. Using SimpleDateFormat and specifying the Locale in the constructor is probably simpler than my earlier suggestion (assuming you can get it to work of course).
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
If I get it working, I'll post my findings.


Interesting - if I use your code but use Décembre it works but I can't get any of the French month abbreviations to work.Of course one could always take the pragmatic approach and use a pre-processor to convert the abbreviations to the standard French months.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic