@Status(stage=DEVELOPMENT, unitTests=COMPLETE) public final class FormatterFactory extends Object
Formatter
does.
Note: This class allows for localized patterns in date/times. In the Netherlands for example we use the pattern: jjjj-mm-dd.
Where the 'jjjj' represents the year. Formatting numbers, never uses a localized pattern. Supply the English pattern instead
to localize numbers. In the Netherlands we use a comma as a decimal separator, so the pattern '##,###,###.##' would format
the number 12345678.90 as '12.345.678,90', using a Dutch locale and as '12,456,78.90' using a US locale.
The patterns for decimals are not localized as they are currently not used in messages.Modifier and Type | Field and Description |
---|---|
static String |
KEY_DATE_PATTERN
Key to the default date pattern in the resource bundle.
|
static String |
KEY_DATE_PATTERN_UNLOCALIZED
Key to the default date pattern in the resource bundle.
|
static String |
KEY_DATE_TIME_PATTERN
Key to the default date/time pattern in the resource bundle.
|
static String |
KEY_DATE_TIME_PATTERN_HMS
Key to the default date/time pattern in the resource bundle.
|
static String |
KEY_DECIMAL_PATTERN
Key to the default decimal number pattern in the resource bundle.
|
static String |
KEY_INTEGER_PATTERN
Key to the default integer number pattern in the resource bundle.
|
static String |
KEY_LOCAL_PATTERN_CHARS
Key to the local pattern characters.
|
static String |
KEY_MONTH_YEAR_PATTERN
Key to the default month/year pattern in the resource bundle.
|
static String |
KEY_MONTH_YEAR_PATTERN_UNLOCALIZED
Key to the default month/year pattern in the resource bundle.
|
static String |
KEY_SHORT_DATE_PATTERN
Key to the default short date pattern in the resource bundle.
|
static String |
KEY_SHORT_DATE_TIME_PATTERN
Key to the default short date/time pattern in the resource bundle.
|
static String |
KEY_TIME_PATTERN
Key to the default time pattern in the resource bundle.
|
Modifier and Type | Method and Description |
---|---|
static NumberFormat |
createBigDecimalFormat(Locale locale,
String pattern)
Creates a
NumberFormat object suitable for formatting and parsing BigDecimal numbers, based upon the supplied
pattern. |
static SimpleDateFormat |
createDateFormat(Locale locale,
String pattern)
Creates a
SimpleDateFormat object suitable for formatting and parsing dates, based upon the supplied pattern. |
static SimpleDateFormat |
createDateTimeFormat(Locale locale,
TimeZone timeZone,
String pattern)
Creates a
SimpleDateFormat object suitable for formatting and parsing date/times, based upon the supplied
pattern. |
static NumberFormat |
createDecimalFormat(Locale locale,
String pattern)
Creates a
NumberFormat object suitable for formatting and parsing decimal numbers, based upon the supplied
pattern. |
static NumberFormat |
createDefaultBigDecimalFormat(Locale locale)
Creates a default
NumberFormat object suitable for formatting and parsing BigDecimal numbers. |
static DateFormat |
createDefaultDateFormat(Locale locale)
Creates a default
DateFormat object suitable for formatting and parsing Dates . |
static DateFormat |
createDefaultDateTimeFormat(Locale locale,
TimeZone timeZone)
Creates a default
DateFormat object suitable for formatting and parsing date/times. |
static NumberFormat |
createDefaultDecimalFormat(Locale locale)
Creates a default
NumberFormat object suitable for formatting and parsing decimal numbers. |
static NumberFormat |
createDefaultIntegerFormat(Locale locale)
Creates a default
NumberFormat object suitable for formatting integer numbers. |
static DateFormat |
createDefaultShortDateFormat(Locale locale)
Creates a default
DateFormat object suitable for formatting and parsing short dates. |
static DateFormat |
createDefaultShortDateTimeFormat(Locale locale,
TimeZone timeZone)
Creates a default
DateFormat object suitable for formatting and parsing short date/times. |
static DateFormat |
createDefaultTimeFormat(Locale locale)
Creates a default
DateFormat object suitable for formatting and parsing times. |
static NumberFormat |
createIntegerFormat(Locale locale,
String pattern)
Creates a
NumberFormat object suitable for formatting and parsing integer numbers, based upon the supplied
pattern. |
static SimpleDateFormat |
createTimeFormat(Locale locale,
String pattern)
Creates a
SimpleDateFormat object suitable for formatting and parsing times, based upon the supplied pattern. |
static String |
getLocalPatternChars(Locale locale)
Gets the local pattern characters that are used to format date/times.
|
static boolean |
isLocalizedPattern(Locale locale,
String pattern)
Determines whether the supplied date/time pattern is a localized pattern or not.
|
public static final String KEY_LOCAL_PATTERN_CHARS
public static final String KEY_DATE_PATTERN
public static final String KEY_DATE_PATTERN_UNLOCALIZED
public static final String KEY_DATE_TIME_PATTERN
public static final String KEY_DATE_TIME_PATTERN_HMS
public static final String KEY_DECIMAL_PATTERN
public static final String KEY_INTEGER_PATTERN
public static final String KEY_MONTH_YEAR_PATTERN
public static final String KEY_MONTH_YEAR_PATTERN_UNLOCALIZED
public static final String KEY_SHORT_DATE_PATTERN
public static final String KEY_SHORT_DATE_TIME_PATTERN
public static final String KEY_TIME_PATTERN
public static DateFormat createDefaultDateFormat(Locale locale)
DateFormat
object suitable for formatting and parsing Dates
.
DateFormat
object is set to not lenient so non existing dates like February 30th won't be
accepted.locale
- Locale to be used for this formatter.DateFormat.SHORT
style is returned.NullPointerException
- When the supplied locale is null.public static DateFormat createDefaultShortDateFormat(Locale locale)
DateFormat
object suitable for formatting and parsing short dates.
DateFormat
object is set to not lenient so non existing dates like February 30th won't be
accepted.locale
- Locale to be used for this formatter.DateFormat.SHORT
style is returned.public static SimpleDateFormat createDateFormat(Locale locale, String pattern)
SimpleDateFormat
object suitable for formatting and parsing dates, based upon the supplied pattern.
SimpleDateFormat
object is set to not lenient so non existing dates won't be accepted.locale
- Locale to be used for this formatter.pattern
- The pattern to use for formatting and parsing dates.
NullPointerException
- When either the supplied locale or pattern is null.public static DateFormat createDefaultDateTimeFormat(Locale locale, TimeZone timeZone)
DateFormat
object suitable for formatting and parsing date/times.
DateFormat
object is set to not lenient so non existing date/times won't be accepted.locale
- Locale to be used for this formatter.timeZone
- Time zone used for this formatter.DateFormat.SHORT
style (for both date and time) is returned.NullPointerException
- When either the supplied locale or timeZone is null.public static DateFormat createDefaultShortDateTimeFormat(Locale locale, TimeZone timeZone)
DateFormat
object suitable for formatting and parsing short date/times.
DateFormat
object is set to not lenient so non existing date/times won't be accepted.locale
- Locale to be used for this formatter.timeZone
- Time zone used for this formatter.DateFormat.SHORT
style (for both date and time) is returned.NullPointerException
- When either the supplied locale or timeZone is null.public static SimpleDateFormat createDateTimeFormat(Locale locale, TimeZone timeZone, String pattern)
SimpleDateFormat
object suitable for formatting and parsing date/times, based upon the supplied
pattern.
SimpleDateFormat
object is set to not lenient so non existing date/times won't be accepted.locale
- Locale to be used for this formatter.timeZone
- Time zone used for this formatter.pattern
- The pattern to use for formatting and parsing date/times.
NullPointerException
- When either the supplied locale, timeZone or pattern is null.public static NumberFormat createDefaultBigDecimalFormat(Locale locale)
NumberFormat
object suitable for formatting and parsing BigDecimal numbers.
createDefaultDecimalFormat(Locale)
, except for
the fact that parsing a value will result in a BigDecimal.locale
- Locale to be used for this formatter.createDefaultDecimalFormat(Locale)
public static NumberFormat createBigDecimalFormat(Locale locale, String pattern)
NumberFormat
object suitable for formatting and parsing BigDecimal numbers, based upon the supplied
pattern.
createDecimalFormat(Locale, String)
, except for
the fact that parsing a value will result in a BigDecimal.locale
- Locale to be used for this formatter.pattern
- The pattern to use for formatting and parsing BigDecimal numbers.public static NumberFormat createDefaultDecimalFormat(Locale locale)
NumberFormat
object suitable for formatting and parsing decimal numbers.
RoundingMode.HALF_UP
rounding.locale
- Locale to be used for this formatter.public static NumberFormat createDecimalFormat(Locale locale, String pattern)
NumberFormat
object suitable for formatting and parsing decimal numbers, based upon the supplied
pattern.
RoundingMode.HALF_UP
rounding.locale
- Locale to be used for this formatter.pattern
- The pattern to use for formatting and parsing decimal numbers.public static NumberFormat createDefaultIntegerFormat(Locale locale)
NumberFormat
object suitable for formatting integer numbers.
RoundingMode.HALF_UP
rounding.locale
- Locale to be used for this formatter.public static NumberFormat createIntegerFormat(Locale locale, String pattern)
NumberFormat
object suitable for formatting and parsing integer numbers, based upon the supplied
pattern.
RoundingMode.HALF_UP
rounding.locale
- Locale to be used for this formatter.pattern
- The pattern to use for formatting and parsing integer numbers.public static DateFormat createDefaultTimeFormat(Locale locale)
DateFormat
object suitable for formatting and parsing times.
DateFormat
object is set to not lenient so non existing times won't be accepted.locale
- Locale to be used for this formatter.DateFormat.SHORT
style is returned.public static SimpleDateFormat createTimeFormat(Locale locale, String pattern)
SimpleDateFormat
object suitable for formatting and parsing times, based upon the supplied pattern.
SimpleDateFormat
object is set to not lenient so non existing times won't be accepted.locale
- Locale to be used for this formatter.pattern
- The pattern to use for formatting and parsing times.
NullPointerException
- When either the supplied locale or pattern is null.public static String getLocalPatternChars(Locale locale)
locale
- Locale to get the local pattern characters for.public static boolean isLocalizedPattern(Locale locale, String pattern)
locale
- Locale used to get the local pattern characters.pattern
- The pattern to check.NullPointerException
- When either the supplied locale or pattern is null.Copyright © 2008–2018. All rights reserved.