Internationalization and localization tools

Locale-Sensitive Java Method


public DateFormatSymbols()

public DateFormatSymbols(Locale locale)

Internationalization (I18n) Method Overview

DateFormatSymbols is a public class for encapsulating localizable date-time formatting data, such as the names of the months, the names of the days of the week, and the time zone data. DateFormat uses DateFormatSymbols to encapsulate this information. Typically you shouldn't use DateFormatSymbols directly. Rather, you are encouraged to create a date-time formatter with the DateFormat class's factory methods: getTimeInstance, getDateInstance, or getDateTimeInstance. These methods automatically create a DateFormatSymbols for the formatter so that you don't have to. However, cases may arise where you must create your own.

This zero-argument constructor produces an instance of DateFormatSymbols specific to the default locale.

I18n Issues

The default machine locale is not always the correct locale for every user. Hence, it is recommended I18n practice to call the constructor that requires a locale argument, to produce an instance that is independent of the machine's default locale.

Globalyzer will detect this method and report it as an I18n issue regardless of the signature used and regardless of whether it is being used correctly. If Locale is already being passed as an argument, Globalyzer will detect it to force developers to double check that the correct Locale is being passed. If you have determined that the call is being handled correctly, you can use Globalyzer's Ignore Comment functionality to ensure that it isn't picked up in a subsequent scan.

Suggested Replacement

public DateFormatSymbols(Locale locale)

Instead of:

DateFormatSymbols symbols =
  new DateFormatSymbols();


Locale locale = getUserLocale();
DateFormatSymbols symbols =
  new DateFormatSymbols(locale);

Please see Times and Dates for more information.

Locale-Sensitive Java Methods


Lingoport internationalization and localization services and software