Package com.oorian.i18n
Class Formatters
java.lang.Object
com.oorian.i18n.Formatters
Locale-aware formatting utilities for dates, times, numbers, and currencies.
All methods that do not take an explicit Locale parameter use
OorianLocale.get() to determine the active locale. Methods are thread-safe
and stateless.
Usage:
OorianLocale.set(Locale.GERMANY);
Formatters.formatDate(LocalDate.now()); // "20.02.2026"
Formatters.formatNumber(1234567.89); // "1.234.567,89"
Formatters.formatCurrency(49.99, Currency.getInstance("EUR")); // "49,99 €"
Formatters.formatPercent(0.85); // "85 %"
- Since:
- 2.1
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatCurrency(Number value, Currency currency) Formats a number as currency using the specified currency and the current locale.static StringformatCurrency(Number value, Currency currency, Locale locale) Formats a number as currency using the specified currency and locale.static StringformatDate(LocalDate date) Formats a date using theMEDIUMstyle and the current locale.static StringformatDate(LocalDate date, FormatStyle style) Formats a date using the specified style and the current locale.static StringformatDate(LocalDate date, FormatStyle style, Locale locale) Formats a date using the specified style and locale.static StringformatDateTime(LocalDateTime dateTime) Formats a date-time using theMEDIUMstyle and the current locale.static StringformatDateTime(LocalDateTime dateTime, FormatStyle style) Formats a date-time using the specified style and the current locale.static StringformatDateTime(LocalDateTime dateTime, FormatStyle style, Locale locale) Formats a date-time using the specified style and locale.static StringformatNumber(Number value) Formats a number using the current locale's default number format.static StringformatNumber(Number value, int decimalPlaces) Formats a number with a fixed number of decimal places using the current locale.static StringformatNumber(Number value, int decimalPlaces, Locale locale) Formats a number with a fixed number of decimal places using the specified locale.static StringformatNumber(Number value, Locale locale) Formats a number using the specified locale's default number format.static StringformatPercent(Number value) Formats a number as a percentage using the current locale.static StringformatPercent(Number value, Locale locale) Formats a number as a percentage using the specified locale.static StringformatTime(LocalTime time) Formats a time using theMEDIUMstyle and the current locale.static StringformatTime(LocalTime time, FormatStyle style) Formats a time using the specified style and the current locale.static StringformatTime(LocalTime time, FormatStyle style, Locale locale) Formats a time using the specified style and locale.static LocalDateparseDate(String text, FormatStyle style) Parses a locale-formatted date string into aLocalDate.static LocalDateparseDate(String text, FormatStyle style, Locale locale) Parses a locale-formatted date string into aLocalDate.static LocalDateTimeparseDateTime(String text, FormatStyle style) Parses a locale-formatted date-time string into aLocalDateTime.static LocalDateTimeparseDateTime(String text, FormatStyle style, Locale locale) Parses a locale-formatted date-time string into aLocalDateTime.static NumberparseNumber(String text) Parses a locale-formatted number string.static NumberparseNumber(String text, Locale locale) Parses a locale-formatted number string using the specified locale.
-
Method Details
-
formatDate
Formats a date using theMEDIUMstyle and the current locale.- Parameters:
date- the date to format- Returns:
- the formatted date string, or an empty string if
dateis null
-
formatDate
Formats a date using the specified style and the current locale.- Parameters:
date- the date to formatstyle- the format style (SHORT, MEDIUM, LONG, FULL)- Returns:
- the formatted date string, or an empty string if
dateis null
-
formatDate
Formats a date using the specified style and locale.- Parameters:
date- the date to formatstyle- the format stylelocale- the locale to use- Returns:
- the formatted date string, or an empty string if
dateis null
-
formatDateTime
Formats a date-time using theMEDIUMstyle and the current locale.- Parameters:
dateTime- the date-time to format- Returns:
- the formatted date-time string, or an empty string if
dateTimeis null
-
formatDateTime
Formats a date-time using the specified style and the current locale.- Parameters:
dateTime- the date-time to formatstyle- the format style- Returns:
- the formatted date-time string, or an empty string if
dateTimeis null
-
formatDateTime
Formats a date-time using the specified style and locale.- Parameters:
dateTime- the date-time to formatstyle- the format stylelocale- the locale to use- Returns:
- the formatted date-time string, or an empty string if
dateTimeis null
-
formatTime
Formats a time using theMEDIUMstyle and the current locale.- Parameters:
time- the time to format- Returns:
- the formatted time string, or an empty string if
timeis null
-
formatTime
Formats a time using the specified style and the current locale.- Parameters:
time- the time to formatstyle- the format style- Returns:
- the formatted time string, or an empty string if
timeis null
-
formatTime
Formats a time using the specified style and locale.- Parameters:
time- the time to formatstyle- the format stylelocale- the locale to use- Returns:
- the formatted time string, or an empty string if
timeis null
-
formatNumber
Formats a number using the current locale's default number format.- Parameters:
value- the number to format- Returns:
- the formatted number string, or an empty string if
valueis null
-
formatNumber
Formats a number using the specified locale's default number format.- Parameters:
value- the number to formatlocale- the locale to use- Returns:
- the formatted number string, or an empty string if
valueis null
-
formatNumber
Formats a number with a fixed number of decimal places using the current locale.- Parameters:
value- the number to formatdecimalPlaces- the number of decimal places- Returns:
- the formatted number string, or an empty string if
valueis null
-
formatNumber
Formats a number with a fixed number of decimal places using the specified locale.- Parameters:
value- the number to formatdecimalPlaces- the number of decimal placeslocale- the locale to use- Returns:
- the formatted number string, or an empty string if
valueis null
-
formatCurrency
Formats a number as currency using the specified currency and the current locale.- Parameters:
value- the monetary amountcurrency- the currency (e.g.,Currency.getInstance("USD"))- Returns:
- the formatted currency string, or an empty string if
valueis null
-
formatCurrency
Formats a number as currency using the specified currency and locale.- Parameters:
value- the monetary amountcurrency- the currencylocale- the locale to use for formatting conventions- Returns:
- the formatted currency string, or an empty string if
valueis null
-
formatPercent
Formats a number as a percentage using the current locale.The value is expected as a fraction (e.g., 0.85 for 85%).
- Parameters:
value- the fractional value- Returns:
- the formatted percentage string, or an empty string if
valueis null
-
formatPercent
Formats a number as a percentage using the specified locale.The value is expected as a fraction (e.g., 0.85 for 85%).
- Parameters:
value- the fractional valuelocale- the locale to use- Returns:
- the formatted percentage string, or an empty string if
valueis null
-
parseDate
Parses a locale-formatted date string into aLocalDate.- Parameters:
text- the text to parsestyle- the format style that was used to format the date- Returns:
- the parsed date, or
nullif the text is null or empty - Throws:
DateTimeParseException- if the text cannot be parsed
-
parseDate
Parses a locale-formatted date string into aLocalDate.- Parameters:
text- the text to parsestyle- the format stylelocale- the locale to use- Returns:
- the parsed date, or
nullif the text is null or empty - Throws:
DateTimeParseException- if the text cannot be parsed
-
parseDateTime
Parses a locale-formatted date-time string into aLocalDateTime.- Parameters:
text- the text to parsestyle- the format style- Returns:
- the parsed date-time, or
nullif the text is null or empty - Throws:
DateTimeParseException- if the text cannot be parsed
-
parseDateTime
Parses a locale-formatted date-time string into aLocalDateTime.- Parameters:
text- the text to parsestyle- the format stylelocale- the locale to use- Returns:
- the parsed date-time, or
nullif the text is null or empty - Throws:
DateTimeParseException- if the text cannot be parsed
-
parseNumber
Parses a locale-formatted number string.- Parameters:
text- the text to parse- Returns:
- the parsed number, or
nullif the text is null or empty - Throws:
ParseException- if the text cannot be parsed
-
parseNumber
Parses a locale-formatted number string using the specified locale.- Parameters:
text- the text to parselocale- the locale to use- Returns:
- the parsed number, or
nullif the text is null or empty - Throws:
ParseException- if the text cannot be parsed
-