public class PeriodFormat
extends java.lang.Object
Period formatting is performed by the PeriodFormatter
class.
Three classes provide factory methods to create formatters, and this is one.
The others are ISOPeriodFormat
and PeriodFormatterBuilder
.
PeriodFormat is thread-safe and immutable, and the formatters it returns are as well.
ISOPeriodFormat
,
PeriodFormatterBuilder
Modifier and Type | Method and Description |
---|---|
static PeriodFormatter |
getDefault()
Gets the default formatter that outputs words in English.
|
static PeriodFormatter |
wordBased()
Returns a word based formatter for the JDK default locale.
|
static PeriodFormatter |
wordBased(java.util.Locale locale)
Returns a word based formatter for the specified locale.
|
public static PeriodFormatter getDefault()
This calls wordBased(Locale)
using a locale of ENGLISH
.
public static PeriodFormatter wordBased()
This calls wordBased(Locale)
using the default locale
.
public static PeriodFormatter wordBased(java.util.Locale locale)
The words are configured in a resource bundle text file -
org.joda.time.format.messages
.
This can be added to via the normal classpath resource bundle mechanisms.
You can add your own translation by creating messages_
Simple example (1 -> singular suffix, not 1 -> plural suffix):
Some languages contain more than two suffixes. You can use regular expressions
for them. Here's an example using regular expression for English:
You can mix both approaches. Here's example for Polish (
"1 year, 2 years, 5 years, 12 years, 15 years, 21 years, 22 years, 25 years"
translates to
"1 rok, 2 lata, 5 lat, 12 lat, 15 lat, 21 lat, 22 lata, 25 lat"). Notice that
PeriodFormat.day and PeriodFormat.days is used for day suffixes as there is no
need for regular expressions:
Each PeriodFormat.<duration_field_type>.regex property stands for an array of
regular expressions and is followed by a property
PeriodFormat.<duration_field_type>.list holding an array of suffixes.
PeriodFormat.regex.separator is used for splitting. See
Available languages are English, Danish, Dutch, French, German, Japanese,
Polish, Portuguese and Spanish.org.joda.time.format.messages
path.
PeriodFormat.space=\
PeriodFormat.comma=,
PeriodFormat.commandand=,and
PeriodFormat.commaspaceand=, and
PeriodFormat.commaspace=,
PeriodFormat.spaceandspace=\ and
PeriodFormat.year=\ year
PeriodFormat.years=\ years
PeriodFormat.month=\ month
PeriodFormat.months=\ months
PeriodFormat.week=\ week
PeriodFormat.weeks=\ weeks
PeriodFormat.day=\ day
PeriodFormat.days=\ days
PeriodFormat.hour=\ hour
PeriodFormat.hours=\ hours
PeriodFormat.minute=\ minute
PeriodFormat.minutes=\ minutes
PeriodFormat.second=\ second
PeriodFormat.seconds=\ seconds
PeriodFormat.millisecond=\ millisecond
PeriodFormat.milliseconds=\ milliseconds
PeriodFormat.space=\
PeriodFormat.comma=,
PeriodFormat.commandand=,and
PeriodFormat.commaspaceand=, and
PeriodFormat.commaspace=,
PeriodFormat.spaceandspace=\ and
PeriodFormat.regex.separator=%
PeriodFormat.years.regex=1$%.*
PeriodFormat.years.list=\ year%\ years
PeriodFormat.months.regex=1$%.*
PeriodFormat.months.list=\ month%\ months
PeriodFormat.weeks.regex=1$%.*
PeriodFormat.weeks.list=\ week%\ weeks
PeriodFormat.days.regex=1$%.*
PeriodFormat.days.list=\ day%\ days
PeriodFormat.hours.regex=1$%.*
PeriodFormat.hours.list=\ hour%\ hours
PeriodFormat.minutes.regex=1$%.*
PeriodFormat.minutes.list=\ minute%\ minutes
PeriodFormat.seconds.regex=1$%.*
PeriodFormat.seconds.list=\ second%\ seconds
PeriodFormat.milliseconds.regex=1$%.*
PeriodFormat.milliseconds.list=\ millisecond%\ milliseconds
PeriodFormat.space=\
PeriodFormat.comma=,
PeriodFormat.commandand=,i
PeriodFormat.commaspaceand=, i
PeriodFormat.commaspace=,
PeriodFormat.spaceandspace=\ i
PeriodFormat.regex.separator=%
PeriodFormat.years.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
PeriodFormat.years.list=\ rok%\ lata%\ lat
PeriodFormat.months.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
PeriodFormat.months.list=\ miesiąc%\ miesiące%\ miesięcy
PeriodFormat.weeks.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
PeriodFormat.weeks.list=\ tydzień%\ tygodnie%\ tygodni
PeriodFormat.day=\ dzień
PeriodFormat.days=\ dni
PeriodFormat.hours.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
PeriodFormat.hours.list=\ godzina%\ godziny%\ godzin
PeriodFormat.minutes.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
PeriodFormat.minutes.list=\ minuta%\ minuty%\ minut
PeriodFormat.seconds.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
PeriodFormat.seconds.list=\ sekunda%\ sekundy%\ sekund
PeriodFormat.milliseconds.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
PeriodFormat.milliseconds.list=\ milisekunda%\ milisekundy%\ milisekund
PeriodFormatterBuilder.appendSuffix(String[], String[])
for details.
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"