Package org.apache.poi.util
Class LocaleUtil
java.lang.Object
org.apache.poi.util.LocaleUtil
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Charset
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 ...)static final TimeZone
Excel doesn't store TimeZone information in the file, so if in doubt, use UTC to perform calculations -
Method Summary
Modifier and TypeMethodDescriptionstatic Calendar
static Calendar
getLocaleCalendar
(int year, int month, int day) Convenience method - month is 0-based as in java.util.Calendarstatic Calendar
getLocaleCalendar
(int year, int month, int day, int hour, int minute, int second) Convenience method - month is 0-based as in java.util.Calendarstatic Calendar
getLocaleCalendar
(TimeZone timeZone) static String
getLocaleFromLCID
(int lcid) Decode the language ID from LCID valuestatic Locale
static TimeZone
static void
static void
Clear the thread-local user time zone.static void
setUserLocale
(Locale locale) Sets default user locale.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.
-
Field Details
-
TIMEZONE_UTC
Excel doesn't store TimeZone information in the file, so if in doubt, use UTC to perform calculations -
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 Details
-
setUserTimeZone
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
- 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
Sets default user locale. This setting is specific to the current thread. -
getUserLocale
- Returns:
- the default user locale. If not set, returns
Locale.getDefault()
.
-
resetUserLocale
public static void resetUserLocale() -
getLocaleCalendar
- Returns:
- a calendar for the user locale and time zone
-
getLocaleCalendar
Convenience method - month is 0-based as in java.util.Calendar- Parameters:
year
-month
-day
-- 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- Parameters:
year
-month
-day
-hour
-minute
-second
-- Returns:
- a calendar for the user locale and time zone, and the given date
-
getLocaleCalendar
- Returns:
- a calendar for the user locale and time zone
-
getLocaleFromLCID
Decode the language ID from LCID value- Parameters:
lcid
- the LCID value- Returns:
- the locale/language ID
-