File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Parsing locale specific Datetime String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parsing locale specific Datetime String" Watch "Parsing locale specific Datetime String" New topic

Parsing locale specific Datetime String

Jammie Jamloki

Joined: Nov 29, 2006
Posts: 1
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

Joined: Aug 05, 2005
Posts: 3742
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

Joined: Feb 06, 2012
Posts: 225

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

Hope this helps..

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46352
And welcome to the Ranch

You are quite a recent arrival if you have only waited 7 years for your first post.
Winston Gutkowski

Joined: Mar 17, 2011
Posts: 8927

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.


Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
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

Joined: Aug 27, 2012
Posts: 1166

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.
I agree. Here's the link:
subject: Parsing locale specific Datetime String
jQuery in Action, 3rd edition