Re: Localizing dates
From: Paul Tomblin (ptomblin+netnews_at_xcski.com)
Date: 01/29/05
- Next message: Heiner Kücker: "Re: JSP functions/methods page question"
- Previous message: Chris: "Localizing dates"
- In reply to: Chris: "Localizing dates"
- Next in thread: anders t: "Re: Localizing dates"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 29 Jan 2005 00:15:09 +0000 (UTC)
In a previous article, "Chris" <anon> said:
>I need to know because I have to parse dates in different locations, and I
>want to give the parser a hint about what format to expect. The default
>parser in DateFormat is lame, so I need to write my own. Specifying a
>format explicitly at run time is not a possibility.
DateFormat isn't that bad for parsing stuff in a file or putting things
output, but I haven't found a good way to parse input dates in a gui.
One thing I had to do in my code: For some bizarre reason, Java thinks
that Italy uses "." between fields in a time stamp, even though our
localization experts and translators said no, we need to use colons like
all the other European languages. So I get the current instance of the
time format, and then if the time is a SimpleDateFormat, make a new
SimpleDateFormat with the dots replaced by colons.
// This is an incredibly ugly hack, but it's based on the fact that
// Java for some reason decided that Italy uses "." between
// hours.minutes.seconds, even though "locale" and strftime say
// something different.
hmsTimeFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM);
if (hmsTimeFormat instanceof SimpleDateFormat)
{
String str = ((SimpleDateFormat)hmsTimeFormat).toPattern();
str = str.replace('.', ':');
hmsTimeFormat = new SimpleDateFormat(str);
}
Maybe you could do a similar trick - get the current date instance, and if
it turns out to be an instanceof SimpleDateFormat, grab the locations of
where each bit is by parsing the pattern.
-- Paul Tomblin <ptomblin@xcski.com> http://xcski.com/blogs/pt/ "Integration by parts -- a very powerful technique." Teaching by intimidation -- also a very powerful technique. -- Logan Shaw, quoting Chuck Odle, his Calculus teacher
- Next message: Heiner Kücker: "Re: JSP functions/methods page question"
- Previous message: Chris: "Localizing dates"
- In reply to: Chris: "Localizing dates"
- Next in thread: anders t: "Re: Localizing dates"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|