Top Description Fields Constructors Methods
org.apache.poi.util

public final Class LocaleUtil

extends Object
Class Inheritance
Imports
java.nio.charset.Charset, java.time.ZoneOffset, java.util.Calendar, .Locale, .TimeZone

This utility class is used to set locale and time zone settings beside of the JDK internal java.util.Locale#setDefault(Locale) and java.util.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 java.lang.ThreadLocal, so they only apply to the current thread and can't be set globally.

Field Summary

Modifier and TypeField and Description
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 ...)

public static final TimeZone
TIMEZONE_UTC

Excel doesn't store TimeZone information in the file, so if in doubt, use UTC to perform calculations

private static final ThreadLocal<Locale>
private static final ThreadLocal<TimeZone>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

the default code page
getDefaultCodePageFromLCID
(int
the LCID value
lcid
)

Get default code page from LCID value

public static Calendar

Returns:

a calendar for the user locale and time zone
getLocaleCalendar
()

public static Calendar

Returns:

a calendar for the user locale and time zone, and the given date
getLocaleCalendar
(int year, int month, int day)

Convenience method - month is 0-based as in java.util.Calendar

public static Calendar

Returns:

a calendar for the user locale and time zone, and the given date
getLocaleCalendar
(int year, int month, int day, int hour, int minute, int second)

Convenience method - month is 0-based as in java.util.Calendar

public static Calendar

Returns:

a calendar for the user locale and time zone
getLocaleCalendar
(TimeZone timeZone)

public static String

Returns:

the locale/language ID
getLocaleFromLCID
(int
the LCID value
lcid
)

Decode the language ID from LCID value

public static Locale

Returns:

the default user locale. If not set, returns Locale#getDefault().
getUserLocale
()

public static TimeZone

Returns:

the time zone which is used for date calculations. If not set, returns TimeZone#getDefault().
getUserTimeZone
()

public static void
public static void
resetUserTimeZone()

Clear the thread-local user time zone.

public static void
setUserLocale(Locale locale)

Sets default user locale.

public static void
setUserTimeZone(TimeZone
the timezone under which date calculations take place
timezone
)

As time zone information is not stored in any format, it can be set before any date calculations take place.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CHARSET_1252back to summary
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 ...)

TIMEZONE_UTCback to summary
public static final TimeZone TIMEZONE_UTC

Excel doesn't store TimeZone information in the file, so if in doubt, use UTC to perform calculations

userLocaleback to summary
private static final ThreadLocal<Locale> userLocale
userTimeZoneback to summary
private static final ThreadLocal<TimeZone> userTimeZone

Constructor Detail

LocaleUtilback to summary
private LocaleUtil()

Method Detail

getDefaultCodePageFromLCIDback to summary
public static int getDefaultCodePageFromLCID(int lcid)

Get default code page from LCID value

Parameters
lcid:int

the LCID value

Returns:int

the default code page

getLocaleCalendarback to summary
public static Calendar getLocaleCalendar()
Returns:Calendar

a calendar for the user locale and time zone

getLocaleCalendarback to summary
public static Calendar getLocaleCalendar(int year, int month, int day)

Convenience method - month is 0-based as in java.util.Calendar

Returns:Calendar

a calendar for the user locale and time zone, and the given date

getLocaleCalendarback to summary
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:Calendar

a calendar for the user locale and time zone, and the given date

getLocaleCalendarback to summary
public static Calendar getLocaleCalendar(TimeZone timeZone)
Returns:Calendar

a calendar for the user locale and time zone

getLocaleFromLCIDback to summary
public static String getLocaleFromLCID(int lcid)

Decode the language ID from LCID value

Parameters
lcid:int

the LCID value

Returns:String

the locale/language ID

getUserLocaleback to summary
public static Locale getUserLocale()
Returns:Locale

the default user locale. If not set, returns Locale#getDefault().

Annotations
@SuppressForbidden:implementation around default locales in POI
getUserTimeZoneback to summary
public static TimeZone getUserTimeZone()
Returns:TimeZone

the time zone which is used for date calculations. If not set, returns TimeZone#getDefault().

Annotations
@SuppressForbidden:implementation around default locales in POI
resetUserLocaleback to summary
public static void resetUserLocale()
resetUserTimeZoneback to summary
public static void resetUserTimeZone()

Clear the thread-local user time zone.

setUserLocaleback to summary
public static void setUserLocale(Locale locale)

Sets default user locale. This setting is specific to the current thread.

setUserTimeZoneback to summary
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:TimeZone

the timezone under which date calculations take place