Re: Localizing dates

From: Paul Tomblin (ptomblin+netnews_at_xcski.com)
Date: 01/29/05


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


Relevant Pages

  • Parsing a file with iterators
    ... I need to parse a file, ... TYPE1 metadata ... When the parser fails to parse one of the lines, ... the format is a dialect of the E00 used in GIS) ...
    (comp.lang.python)
  • Re: How to subtract dates ?
    ... > Dates have this format 2004.10.12 ... > How to subtract it and get result in days. ... You can use a SimpleDateFormat to parse that into ...
    (comp.lang.java.programmer)
  • Re: corrupted pointer when initing a dll
    ... then call parser to parse the a2l file and load all the channel ... return result of the load and parse. ... class is housed in a DLL and that DLL can be unloaded while your ...
    (microsoft.public.vc.language)
  • Re: corrupted pointer when initing a dll
    ... then call parser to parse the a2l file and load all the channel ... return result of the load and parse. ... class is housed in a DLL and that DLL can be unloaded while your ...
    (microsoft.public.vc.language)
  • Re: Parse library
    ... special case the Value state code-path. ... The html doco on bind are available at ... My format might support something like: ... With a parser module, you'd ...
    (microsoft.public.dotnet.languages.csharp)