java.lang.Object | |
↳ | org.joda.time.format.PeriodFormatter |
Controls the printing and parsing of a time period to and from a string.
This class is the main API for printing and parsing used by most applications. Instances of this class are created via one of three factory classes:
PeriodFormat
- formats by pattern and styleISOPeriodFormat
- ISO8601 formatsPeriodFormatterBuilder
- complex formats created via method calls
An instance of this class holds a reference internally to one printer and
one parser. It is possible that one of these may be null, in which case the
formatter cannot print/parse. This can be checked via the isPrinter()
and isParser()
methods.
The underlying printer/parser can be altered to behave exactly as required by using a decorator modifier:
withLocale(Locale)
- returns a new formatter that uses the specified locale
The main methods of the class are the printXxx
and
parseXxx
methods. These are used as follows:
// print using the default locale String periodStr = formatter.print(period); // print using the French locale String periodStr = formatter.withLocale(Locale.FRENCH).print(period); // parse using the French locale Period date = formatter.withLocale(Locale.FRENCH).parsePeriod(str);
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new formatter, however you will normally use the factory
or the builder.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the locale that will be used for printing and parsing.
| |||||||||||
Gets the PeriodType that will be used for parsing.
| |||||||||||
Gets the internal parser object that performs the real parsing work.
| |||||||||||
Gets the internal printer object that performs the real printing work.
| |||||||||||
Is this formatter capable of parsing.
| |||||||||||
Is this formatter capable of printing.
| |||||||||||
Parses a period from the given text, at the given position, saving the
result into the fields of the given ReadWritablePeriod.
| |||||||||||
Parses a period from the given text, returning a new MutablePeriod.
| |||||||||||
Parses a period from the given text, returning a new Period.
| |||||||||||
Prints a ReadablePeriod to a new String.
| |||||||||||
Prints a ReadablePeriod to a StringBuffer.
| |||||||||||
Prints a ReadablePeriod to a Writer.
| |||||||||||
Returns a new formatter with a different locale that will be used
for printing and parsing.
| |||||||||||
Returns a new formatter with a different PeriodType for parsing.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Creates a new formatter, however you will normally use the factory or the builder.
printer | the internal printer, null if cannot print |
---|---|
parser | the internal parser, null if cannot parse |
Gets the locale that will be used for printing and parsing.
Gets the PeriodType that will be used for parsing.
Gets the internal parser object that performs the real parsing work.
Gets the internal printer object that performs the real printing work.
Is this formatter capable of parsing.
Is this formatter capable of printing.
Parses a period from the given text, at the given position, saving the result into the fields of the given ReadWritablePeriod. If the parse succeeds, the return value is the new text position. Note that the parse may succeed without fully reading the text.
The parse type of the formatter is not used by this method.
If it fails, the return value is negative, but the period may still be modified. To determine the position where the parse failed, apply the one's complement operator (~) on the return value.
period | a period that will be modified |
---|---|
text | text to parse |
position | position to start parsing from |
IllegalArgumentException | if any field is out of range |
---|
Parses a period from the given text, returning a new MutablePeriod.
text | text to parse |
---|
IllegalArgumentException | if any field is out of range |
---|
Parses a period from the given text, returning a new Period.
text | text to parse |
---|
IllegalArgumentException | if any field is out of range |
---|
Prints a ReadablePeriod to a new String.
period | the period to format, not null |
---|
Prints a ReadablePeriod to a StringBuffer.
buf | the formatted period is appended to this buffer |
---|---|
period | the period to format, not null |
Prints a ReadablePeriod to a Writer.
out | the formatted period is written out |
---|---|
period | the period to format, not null |
IOException |
---|
Returns a new formatter with a different locale that will be used for printing and parsing.
A PeriodFormatter is immutable, so a new instance is returned, and the original is unaltered and still usable.
locale | the locale to use |
---|
Returns a new formatter with a different PeriodType for parsing.
A PeriodFormatter is immutable, so a new instance is returned, and the original is unaltered and still usable.
type | the type to use in parsing |
---|