Thanks,
Jonathan
import java.util.*;
import java.text.*;
public class LocaleTest
{
public static void main(String[] args)
{
DateFormat format = DateFormat.getDateInstanc(DateFormat.SHORT);
format.setCalendar(Calendar.getInstance());
format.getCalendar().set(Calendar.MILLISECOND,0);
format.getCalendar().set(Calendar.SECOND,0);
format.getCalendar().set(Calendar.MINUTE,0);
format.getCalendar().set(Calendar.HOUR,0);
System.out.println("date is "+
format.format(format.getCalendar().getTime()));
}
}
> I'm having issues dealing with Locale under 1.4.1_03-b02. The problem
> seems to be with the Java Runtime having problems reading the system
> locale. My system locale is set to UK, but when I run a test program
> (code below) I get the date formatted to a US locale instead of UK. I
> ran the same program under 1.4.2_03 on win xp, and 1.4.2_04-b05 on
> win2k which both worked fine. Running the same program under 1.4.1_03
> on win xp and win 2k results in the problem. Does anyone know of a
> workaround to this problem without upgrading to 1.4.2_03 or higher?
Start your program with
java -Duser.language=en -Duser.country=GB ...
Note: GB, not UK
> Also does anyone know what the minimum version we should have if we
> did decide to upgrade JRE's?
Don't know, but I'd go for the latest release of 1.4.2 (which is _05 at the time of this writing).
The release notes normally contain a list of bugs that have been fixed by that release.
> [snip]
--
Regards,
Z.
Thanks for the information, but unfortunately I can't upgrade or have
hardcoded command line arguments. The reason is because my users
won't go for the upgrade and they're located all over the world. Do
you know of a workaround that uses the systems locale and the date
formatter will properly use it too?
There's not much that I can think of, considering these restrictions.
You could check the Java bugdatabase to see if there are workarounds for the problem.
As you probably know, you can programmatically change the default locale (Locale.setDefault(...)),
but that maybe would mean that you have to change your program and have the users upgraded (well,
with new version of your program, not the JRE), a way you seemed no to want to go.
Otherwise you could play around with Window's regional settings, and see if that brings a solution.
Yet, then you would have to instruct every user to change their settings, possibly causing problems
with other applications they have. So, this doesn't seem the proper direction either.
--
Regards,
Z.
Thanks again for the update. I realized I was incorrect with the
original issue. It seems that the JRE 1.4.1 does pick up the correct
Locale, but either the DateFormat and/or Calendar classes are ignoring
the Locale. Do you have any suggestions/workarounds in getting the
DateFormat and/or Calendar to acknowledge the correct Locale?
Jonathan
> [snip]
> Thanks again for the update. I realized I was incorrect with the
> original issue. It seems that the JRE 1.4.1 does pick up the correct
> Locale, but either the DateFormat and/or Calendar classes are ignoring
> the Locale. Do you have any suggestions/workarounds in getting the
> DateFormat and/or Calendar to acknowledge the correct Locale?
>
> Jonathan
IIRC there's
DateFormat.getDateInstance(format,locale)
and
Calender.getInstance(locale)
--
Regards,
Z.
Thanks for all the assistance. It turns out there wasn't a problem
with any of the classes that I mentioned. The problem was that we're
using the US version of 1.4.1 and not the international version.
Sorry for the mistake.
Jonathan
Yep, that explains a lot...
> Sorry for the mistake.
Not at all, something to keep in mind for me too ;-)
--
Regards,
Z.