Internationalization and localization tools

Locale-Sensitive Java Method


public static final DateFormat getTimeInstance()

public static final DateFormat getTimeInstance(int style)

public static final DateFormat getTimeInstance(int style,
   Locale aLocale)

Internationalization (I18n) Method Overview

DateFormat helps you to format and parse dates and times for any locale. Your code can be completely independent of the locale conventions for months, days of the week, or even the calendar format: lunar vs. solar. Both of these factory methods produce a DateFormat object that will format a time string according to the rules of the default locale. The signature that accepts a style int also formats it according to the given style, i.e. SHORT for "h:mm a" in the US 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 factory method that takes both a style and locale argument, allowing the code to format a time independently 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 static final DateFormat getTimeInstance(int style,
   Locale aLocale)

Instead of:

DateFormat dateFormatter =


DateFormat dateFormatter =


Locale locale = getUserLocale();
DateFormat dateFormatter =
  DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);

Please see Times and Dates for more information.

Locale-Sensitive Java Methods


Lingoport internationalization and localization services and software