Class FormatHelper
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordPatterns to initialize formatting. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyPatterns(Locale locale, FormatHelper.Patterns patterns) Applies a set of patterns to a locale.static voidapplyPatterns(FormatHelper.Patterns patterns) Applies a set of patterns to the current locale.static StringcalendarFieldToString(int field, boolean plural) Translates a field ofCalendarto a localized string.static StringdebitCreditToString(BMoney money, boolean debit) Translates a money value to a string with a suffix indicating whether debit or credit.static intdetermineScale(String value) Determines the scale from a given numeric string.static StringformatDate(Date date) Formats a date.static StringformatFloatingNumber(Number number) Formats a floating number.static StringformatInteger(Number number) Formats an integer.static StringformatLocalDate(LocalDate date) Formats a date.static StringformatLocalDateTime(LocalDateTime timestamp) Formats a timestamp.static StringformatLocalTime(LocalTime time) Formats a time.static StringformatOffsetDateTime(OffsetDateTime timestamp) Formats a timestamp with zone offset.static StringformatOffsetTime(OffsetTime time) Formats a time with zone offset.static StringformatShortDate(Date date) Formats a short date.static StringFormats a short date.static StringformatShortLocalDateTime(LocalDateTime timestamp) Formats a short timestamp.static StringFormats a short time.static StringformatShortOffsetDateTime(OffsetDateTime timestamp) Formats a short timestamp with zone offset.static StringFormats a short time with zone offset.static StringformatShortTime(Date time) Formats a short time.static StringformatShortTimestamp(Date timestamp) Formats a short timestamp.static StringformatShortZonedDateTime(ZonedDateTime timestamp) Formats a short timestamp with timezone.static StringformatTime(Date time) Formats a time.static StringformatTimestamp(Date timestamp) Formats a timestamp.static StringformatZonedDateTime(ZonedDateTime timestamp) Formats a timestamp with timezone.static StringGets the date pattern.static StringgetDatePattern(Locale locale) Gets the date pattern.static StringGets the floating number pattern.static StringgetFloatingNumberPattern(Locale locale) Gets the floating number pattern.static StringGets the integer pattern.static StringgetIntegerPattern(Locale locale) Gets the integer pattern.static DateTimeFormatterGets the formatter for a LocalDate.static DateTimeFormattergetLocalDateFormatter(Locale locale) Gets the formatter for a LocalDate.static DateTimeFormatterGets the formatter for a LocalDateTime.static DateTimeFormattergetLocalDateTimeFormatter(Locale locale) Gets the formatter for a LocalDateTime.static DateTimeFormatterGets the formatter for a LocalTime.static DateTimeFormattergetLocalTimeFormatter(Locale locale) Gets the formatter for a LocalTime.static StringGets the money pattern.static StringgetMoneyPattern(Locale locale) Gets the money pattern.static DateTimeFormatterGets the formatter for an OffsetDateTime.static DateTimeFormattergetOffsetDateTimeFormatter(Locale locale) Gets the formatter for an OffsetDateTime.static DateTimeFormatterGets the formatter for an OffsetTime.static DateTimeFormattergetOffsetTimeFormatter(Locale locale) Gets the formatter for an OffsetTime.static StringGets the short date pattern.static StringgetShortDatePattern(Locale locale) Gets the short date pattern.static DateTimeFormatterGets the formatter for a short LocalDate.static DateTimeFormattergetShortLocalDateFormatter(Locale locale) Gets the formatter for a short LocalDate.static DateTimeFormatterGets the formatter for a short LocalDateTime.static DateTimeFormattergetShortLocalDateTimeFormatter(Locale locale) Gets the formatter for a short LocalDateTime.static DateTimeFormatterGets the formatter for a short LocalTime.static DateTimeFormattergetShortLocalTimeFormatter(Locale locale) Gets the formatter for a short LocalTime.static DateTimeFormatterGets the formatter for a short OffsetDateTime.static DateTimeFormatterGets the formatter for a short OffsetDateTime.static DateTimeFormatterGets the formatter for a short OffsetTime.static DateTimeFormattergetShortOffsetTimeFormatter(Locale locale) Gets the formatter for a short OffsetTime.static StringGets the short time pattern.static StringgetShortTimePattern(Locale locale) Gets the short time pattern.static StringGets the short time pattern with zone offset.static StringgetShortTimePatternWithOffset(Locale locale) Gets the short time pattern with zone offset.static StringGets the short timestamp pattern.static StringgetShortTimestampPattern(Locale locale) Gets the short timestamp pattern.static StringGets the short timestamp pattern with offset.static StringGets the short timestamp pattern with zone offsetstatic StringGets the short timestamp pattern with timezone.static StringGets the short timestamp pattern with timezone.static DateTimeFormatterGets the formatter for a short ZonedDateTime.static DateTimeFormattergetShortZonedDateTimeFormatter(Locale locale) Gets the formatter for a short ZonedDateTime.static StringGets the time pattern.static StringgetTimePattern(Locale locale) Gets the time pattern.static StringGets the time pattern with zone offset.static StringgetTimePatternWithOffset(Locale locale) Gets the time pattern with zone offset.static StringGets the timestamp pattern.static StringgetTimestampPattern(Locale locale) Gets the timestamp pattern.static StringGets the timestamp pattern with zone offset.static StringgetTimestampPatternWithOffset(Locale locale) Gets the timestamp pattern with zone offset.static StringGets the timestamp pattern with timezone.static StringGets the timestamp pattern with timezonestatic DateTimeFormatterGets the formatter for a ZonedDateTime.static DateTimeFormattergetZonedDateTimeFormatter(Locale locale) Gets the formatter for a ZonedDateTime.static booleanisFormattingDate(String pattern) Checks whether format pattern contains formatting codes for date.static booleanisFormattingOffset(String pattern) Checks whether format pattern contains formatting codes for the zone offset.static booleanisFormattingTime(String pattern) Checks whether format pattern contains formatting codes for time.static booleanisFormattingTimeZone(String pattern) Checks whether format pattern contains formatting codes for the timezone.static DateParses a date.static doubleparseDouble(String str) Parses a double.static floatparseFloat(String str) Parses a float.static intparseInteger(String str) Parses an integer.static LocalDateparseLocalDate(String str) Parses a date.static LocalDateTimeparseLocalDateTime(String str) Parses a timestamp.static LocalTimeparseLocalTime(String str) Parses a time.static OffsetDateTimeParses a timestamp with zone offset.static OffsetTimeparseOffsetTime(String str) Parses a time with zone offset.static DateparseShortDate(String str) Parses a short date.static LocalDateParses a short date.static LocalDateTimeParses a short timestamp.static LocalTimeParses a short time.static OffsetDateTimeParses a short timestamp with zone offset.static OffsetTimeParses short a time with zone offset.static TimeparseShortTime(String str) Parses a short time.static TimestampParses a short timestamp.static ZonedDateTimeParses a short timestamp with timezone.static TimeParses a time.static TimestampparseTimestamp(String str) Parses a timestamp.static ZonedDateTimeparseZonedDateTime(String str) Parses a timestamp with timezone.static voidsetScale(DecimalFormat format, int scale) Changes the decimal format according to the given scale.
Leaves the part before the comma unchanged!
-
Method Details
-
applyPatterns
Applies a set of patterns to a locale.- Parameters:
locale- the localepatterns- the patterns
-
applyPatterns
Applies a set of patterns to the current locale.- Parameters:
patterns- the patterns
-
getIntegerPattern
-
getFloatingNumberPattern
-
getMoneyPattern
-
getTimestampPattern
-
getTimestampPatternWithOffset
-
getTimestampPatternWithTimeZone
-
getShortTimestampPattern
-
getShortTimestampPatternWithOffset
-
getShortTimestampPatternWithTimeZone
-
getDatePattern
-
getShortDatePattern
-
getTimePattern
-
getTimePatternWithOffset
-
getShortTimePattern
-
getShortTimePatternWithOffset
-
getIntegerPattern
-
getFloatingNumberPattern
Gets the floating number pattern.- Returns:
- the pattern
-
getMoneyPattern
-
getTimestampPattern
-
getTimestampPatternWithOffset
Gets the timestamp pattern with zone offset.- Returns:
- the pattern
-
getTimestampPatternWithTimeZone
Gets the timestamp pattern with timezone.- Returns:
- the pattern
-
getShortTimestampPattern
Gets the short timestamp pattern.- Returns:
- the pattern
-
getShortTimestampPatternWithOffset
Gets the short timestamp pattern with offset.- Returns:
- the pattern
-
getShortTimestampPatternWithTimeZone
Gets the short timestamp pattern with timezone.- Returns:
- the pattern
-
getDatePattern
-
getShortDatePattern
-
getTimePattern
-
getTimePatternWithOffset
Gets the time pattern with zone offset.- Returns:
- the pattern
-
getShortTimePattern
-
getShortTimePatternWithOffset
Gets the short time pattern with zone offset.- Returns:
- the pattern
-
parseInteger
Parses an integer.- Parameters:
str- the string to parse- Returns:
- the number
- Throws:
ParseException- if parsing failed
-
parseFloat
Parses a float.- Parameters:
str- the string to parse- Returns:
- the number
- Throws:
ParseException- if parsing failed
-
parseDouble
Parses a double.- Parameters:
str- the string to parse- Returns:
- the number
- Throws:
ParseException- if parsing failed
-
parseTimestamp
Parses a timestamp.Throws
DateTimeParseExceptionif parsing failed.- Parameters:
str- the string to parse- Returns:
- the timestamp
-
parseShortTimestamp
Parses a short timestamp.Throws
DateTimeParseExceptionif parsing failed.- Parameters:
str- the string to parse- Returns:
- the timestamp
-
parseDate
Parses a date.Throws
DateTimeParseExceptionif parsing failed.- Parameters:
str- the string to parse- Returns:
- the date
-
parseShortDate
Parses a short date.Throws
DateTimeParseExceptionif parsing failed.- Parameters:
str- the string to parse- Returns:
- the date
-
parseTime
Parses a time.Throws
DateTimeParseExceptionif parsing failed.- Parameters:
str- the string to parse- Returns:
- the time
-
parseShortTime
Parses a short time.Throws
DateTimeParseExceptionif parsing failed.- Parameters:
str- the string to parse- Returns:
- the time
-
parseLocalDateTime
Parses a timestamp.Throws java.time.format.DateTimeParseException if parsing failed
- Parameters:
str- the string to parse- Returns:
- the timestamp
-
parseOffsetDateTime
Parses a timestamp with zone offset.Throws java.time.format.DateTimeParseException if parsing failed
- Parameters:
str- the string to parse- Returns:
- the timestamp
-
parseZonedDateTime
Parses a timestamp with timezone.Throws java.time.format.DateTimeParseException if parsing failed
- Parameters:
str- the string to parse- Returns:
- the timestamp
-
parseShortLocalDateTime
Parses a short timestamp.Throws java.time.format.DateTimeParseException if parsing failed
- Parameters:
str- the string to parse- Returns:
- the timestamp
-
parseShortOffsetDateTime
Parses a short timestamp with zone offset.Throws java.time.format.DateTimeParseException if parsing failed
- Parameters:
str- the string to parse- Returns:
- the timestamp
-
parseShortZonedDateTime
Parses a short timestamp with timezone.Throws java.time.format.DateTimeParseException if parsing failed
- Parameters:
str- the string to parse- Returns:
- the timestamp
-
parseLocalDate
-
parseShortLocalDate
-
parseLocalTime
-
parseOffsetTime
Parses a time with zone offset.Throws java.time.format.DateTimeParseException if parsing failed
- Parameters:
str- the string to parse- Returns:
- the time
-
parseShortLocalTime
-
parseShortOffsetTime
Parses short a time with zone offset.Throws java.time.format.DateTimeParseException if parsing failed
- Parameters:
str- the string to parse- Returns:
- the time
-
formatInteger
-
formatFloatingNumber
-
formatTimestamp
-
formatShortTimestamp
-
formatDate
-
formatShortDate
-
formatTime
-
formatShortTime
-
formatLocalDateTime
Formats a timestamp.- Parameters:
timestamp- the timestamp to format- Returns:
- the formatted string
-
formatOffsetDateTime
Formats a timestamp with zone offset.- Parameters:
timestamp- the timestamp to format- Returns:
- the formatted string
-
formatZonedDateTime
Formats a timestamp with timezone.- Parameters:
timestamp- the timestamp to format- Returns:
- the formatted string
-
formatShortLocalDateTime
Formats a short timestamp.- Parameters:
timestamp- the timestamp to format- Returns:
- the formatted string
-
formatShortOffsetDateTime
Formats a short timestamp with zone offset.- Parameters:
timestamp- the timestamp to format- Returns:
- the formatted string
-
formatShortZonedDateTime
Formats a short timestamp with timezone.- Parameters:
timestamp- the timestamp to format- Returns:
- the formatted string
-
formatLocalDate
-
formatShortLocalDate
-
formatLocalTime
-
formatOffsetTime
Formats a time with zone offset.- Parameters:
time- the time to format- Returns:
- the formatted string
-
formatShortLocalTime
-
formatShortOffsetTime
Formats a short time with zone offset.- Parameters:
time- the time to format- Returns:
- the formatted string
-
getLocalDateTimeFormatter
Gets the formatter for a LocalDateTime.- Returns:
- the immutable and thread-safe formatter
-
getOffsetDateTimeFormatter
Gets the formatter for an OffsetDateTime.- Returns:
- the immutable and thread-safe formatter
-
getZonedDateTimeFormatter
Gets the formatter for a ZonedDateTime.- Returns:
- the immutable and thread-safe formatter
-
getLocalDateFormatter
Gets the formatter for a LocalDate.- Returns:
- the immutable and thread-safe formatter
-
getLocalTimeFormatter
Gets the formatter for a LocalTime.- Returns:
- the immutable and thread-safe formatter
-
getOffsetTimeFormatter
Gets the formatter for an OffsetTime.- Returns:
- the immutable and thread-safe formatter
-
getShortLocalDateTimeFormatter
Gets the formatter for a short LocalDateTime.- Returns:
- the immutable and thread-safe formatter
-
getShortOffsetDateTimeFormatter
Gets the formatter for a short OffsetDateTime.- Returns:
- the immutable and thread-safe formatter
-
getShortZonedDateTimeFormatter
Gets the formatter for a short ZonedDateTime.- Returns:
- the immutable and thread-safe formatter
-
getShortLocalDateFormatter
Gets the formatter for a short LocalDate.- Returns:
- the immutable and thread-safe formatter
-
getShortLocalTimeFormatter
Gets the formatter for a short LocalTime.- Returns:
- the immutable and thread-safe formatter
-
getShortOffsetTimeFormatter
Gets the formatter for a short OffsetTime.- Returns:
- the immutable and thread-safe formatter
-
getLocalDateTimeFormatter
Gets the formatter for a LocalDateTime.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
getOffsetDateTimeFormatter
Gets the formatter for an OffsetDateTime.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
getZonedDateTimeFormatter
Gets the formatter for a ZonedDateTime.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
getLocalDateFormatter
Gets the formatter for a LocalDate.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
getLocalTimeFormatter
Gets the formatter for a LocalTime.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
getOffsetTimeFormatter
Gets the formatter for an OffsetTime.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
getShortLocalDateTimeFormatter
Gets the formatter for a short LocalDateTime.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
getShortOffsetDateTimeFormatter
Gets the formatter for a short OffsetDateTime.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
getShortZonedDateTimeFormatter
Gets the formatter for a short ZonedDateTime.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
getShortLocalDateFormatter
Gets the formatter for a short LocalDate.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
getShortLocalTimeFormatter
Gets the formatter for a short LocalTime.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
getShortOffsetTimeFormatter
Gets the formatter for a short OffsetTime.- Parameters:
locale- the locale- Returns:
- the immutable and thread-safe formatter
-
determineScale
Determines the scale from a given numeric string.Does not work with scientific number strings.
- Parameters:
value- the numeric string- Returns:
- the scale
-
setScale
Changes the decimal format according to the given scale.
Leaves the part before the comma unchanged!- Parameters:
format- the decimal formatscale- the scale
-
debitCreditToString
Translates a money value to a string with a suffix indicating whether debit or credit. Commonly used in financial accounting applications.- Parameters:
money- the amount of moneydebit- true if the amount is debit, else credit- Returns:
- the formatted value
-
isFormattingTime
Checks whether format pattern contains formatting codes for time.- Parameters:
pattern- the format pattern- Returns:
- true if contains time-formatting
-
isFormattingDate
Checks whether format pattern contains formatting codes for date.- Parameters:
pattern- the format pattern- Returns:
- true if contains date-formatting
-
isFormattingOffset
Checks whether format pattern contains formatting codes for the zone offset.- Parameters:
pattern- the format pattern- Returns:
- true if contains zone-offset formatting
-
isFormattingTimeZone
Checks whether format pattern contains formatting codes for the timezone.- Parameters:
pattern- the format pattern- Returns:
- true if contains timezone formatting
-
calendarFieldToString
Translates a field ofCalendarto a localized string.Example:
Calendar.DAY_OF_MONTHwill be translated to "month".Notice that only the following field types are supported:
- Parameters:
field- the field typeplural- true if plural, else singular- Returns:
- the name, the empty string if unsupported field type
-