Class LocaleUtil


  • public final class LocaleUtil
    extends Object
    This utility class is used to set locale and time zone settings beside of the JDK internal Locale.setDefault(Locale) and TimeZone.setDefault(TimeZone) methods, because the locale/time zone specific handling of certain office documents - maybe for different time zones / locales ... - shouldn't affect other java components. The settings are saved in a ThreadLocal, so they only apply to the current thread and can't be set globally.
    • Field Detail

      • TIMEZONE_UTC

        public static final TimeZone TIMEZONE_UTC
        Excel doesn't store TimeZone information in the file, so if in doubt, use UTC to perform calculations
      • CHARSET_1252

        public static final Charset CHARSET_1252
        Default encoding for unknown byte encodings of native files (at least it's better than to rely on a platform dependent encoding for legacy stuff ...)
    • Method Detail

      • setUserTimeZone

        public static void setUserTimeZone​(TimeZone timezone)
        As time zone information is not stored in any format, it can be set before any date calculations take place. This setting is specific to the current thread.
        Parameters:
        timezone - the timezone under which date calculations take place
      • getUserTimeZone

        public static TimeZone getUserTimeZone()
        Returns:
        the time zone which is used for date calculations. If not set, returns TimeZone.getDefault().
      • resetUserTimeZone

        public static void resetUserTimeZone()
        Clear the thread-local user time zone.
      • setUserLocale

        public static void setUserLocale​(Locale locale)
        Sets default user locale. This setting is specific to the current thread.
      • getUserLocale

        public static Locale getUserLocale()
        Returns:
        the default user locale. If not set, returns Locale.getDefault().
      • resetUserLocale

        public static void resetUserLocale()
      • getLocaleCalendar

        public static Calendar getLocaleCalendar()
        Returns:
        a calendar for the user locale and time zone
      • getLocaleCalendar

        public static Calendar getLocaleCalendar​(int year,
                                                 int month,
                                                 int day)
        Convenience method - month is 0-based as in java.util.Calendar
        Returns:
        a calendar for the user locale and time zone, and the given date
      • getLocaleCalendar

        public static Calendar getLocaleCalendar​(int year,
                                                 int month,
                                                 int day,
                                                 int hour,
                                                 int minute,
                                                 int second)
        Convenience method - month is 0-based as in java.util.Calendar
        Returns:
        a calendar for the user locale and time zone, and the given date
      • getLocaleCalendar

        public static Calendar getLocaleCalendar​(TimeZone timeZone)
        Returns:
        a calendar for the user locale and time zone
      • getLocaleFromLCID

        public static String getLocaleFromLCID​(int lcid)
        Decode the language ID from LCID value
        Parameters:
        lcid - the LCID value
        Returns:
        the locale/language ID
      • getDefaultCodePageFromLCID

        public static int getDefaultCodePageFromLCID​(int lcid)
        Get default code page from LCID value
        Parameters:
        lcid - the LCID value
        Returns:
        the default code page