java.lang.Object | |
↳ | org.joda.time.format.DateTimeFormatterBuilder |
Factory that creates complex instances of DateTimeFormatter via method calls.
Datetime formatting is performed by the DateTimeFormatter
class.
Three classes provide factory methods to create formatters, and this is one.
The others are DateTimeFormat
and ISODateTimeFormat
.
DateTimeFormatterBuilder is used for constructing formatters which are then used to print or parse. The formatters are built by appending specific fields or other formatters to an instance of this builder.
For example, a formatter that prints month and year, like "January 1970", can be constructed as follows:
DateTimeFormatter monthAndYear = new DateTimeFormatterBuilder() .appendMonthOfYearText() .appendLiteral(' ') .appendYear(4, 4) .toFormatter();
DateTimeFormatterBuilder itself is mutable and not thread-safe, but the formatters that it builds are thread-safe and immutable.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a DateTimeFormatterBuilder.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Appends a printer and a set of matching parsers.
| |||||||||||
Appends a printer/parser pair.
| |||||||||||
Appends another formatter.
| |||||||||||
Appends just a printer.
| |||||||||||
Appends just a parser.
| |||||||||||
Instructs the printer to emit a numeric century of era field.
| |||||||||||
Instructs the printer to emit a numeric clockhourOfDay field.
| |||||||||||
Instructs the printer to emit a numeric clockhourOfHalfday field.
| |||||||||||
Instructs the printer to emit a numeric dayOfMonth field.
| |||||||||||
Instructs the printer to emit a numeric dayOfWeek field.
| |||||||||||
Instructs the printer to emit a short locale-specific dayOfWeek
text.
| |||||||||||
Instructs the printer to emit a locale-specific dayOfWeek text.
| |||||||||||
Instructs the printer to emit a numeric dayOfYear field.
| |||||||||||
Instructs the printer to emit a field value as a decimal number, and the
parser to expect an unsigned decimal number.
| |||||||||||
Instructs the printer to emit a locale-specific era text (BC/AD), and
the parser to expect it.
| |||||||||||
Instructs the printer to emit a field value as a fixed-width decimal
number (smaller numbers will be left-padded with zeros), and the parser
to expect an unsigned decimal number with the same fixed width.
| |||||||||||
Instructs the printer to emit a field value as a fixed-width decimal
number (smaller numbers will be left-padded with zeros), and the parser
to expect an signed decimal number with the same fixed width.
| |||||||||||
Instructs the printer to emit a remainder of time as a decimal fraction,
sans decimal point.
| |||||||||||
Instructs the printer to emit a locale-specific AM/PM text, and the
parser to expect it.
| |||||||||||
Instructs the printer to emit a numeric hourOfDay field.
| |||||||||||
Instructs the printer to emit a numeric hourOfHalfday field.
| |||||||||||
Instructs the printer to emit specific text, and the parser to expect
it.
| |||||||||||
Instructs the printer to emit a specific character, and the parser to
expect it.
| |||||||||||
Instructs the printer to emit a numeric millisOfDay field.
| |||||||||||
Instructs the printer to emit a numeric millisOfSecond field.
| |||||||||||
Instructs the printer to emit a numeric minuteOfDay field.
| |||||||||||
Instructs the printer to emit a numeric minuteOfHour field.
| |||||||||||
Instructs the printer to emit a numeric monthOfYear field.
| |||||||||||
Instructs the printer to emit a locale-specific monthOfYear text.
| |||||||||||
Instructs the printer to emit a short locale-specific monthOfYear
text.
| |||||||||||
Appends just a parser element which is optional.
| |||||||||||
Calls upon
DateTimeFormat to parse the pattern and append the
results into this builder. | |||||||||||
Instructs the printer to emit a numeric secondOfDay field.
| |||||||||||
Instructs the printer to emit a numeric secondOfMinute field.
| |||||||||||
Instructs the printer to emit a field value as short text, and the
parser to expect text.
| |||||||||||
Instructs the printer to emit a field value as a decimal number, and the
parser to expect a signed decimal number.
| |||||||||||
Instructs the printer to emit a field value as text, and the
parser to expect text.
| |||||||||||
Instructs the printer to emit the identifier of the time zone.
| |||||||||||
Instructs the printer to emit a locale-specific time zone name.
| |||||||||||
Instructs the printer to emit text and numbers to display time zone
offset from UTC.
| |||||||||||
Instructs the printer to emit a short locale-specific time zone
name.
| |||||||||||
Instructs the printer to emit a numeric weekyear field which always prints
and parses two digits.
| |||||||||||
Instructs the printer to emit a numeric weekyear field which always prints
two digits.
| |||||||||||
Instructs the printer to emit a numeric year field which always prints
two digits.
| |||||||||||
Instructs the printer to emit a numeric year field which always prints
and parses two digits.
| |||||||||||
Instructs the printer to emit a numeric weekOfWeekyear field.
| |||||||||||
Instructs the printer to emit a numeric weekyear field.
| |||||||||||
Instructs the printer to emit a numeric year field.
| |||||||||||
Instructs the printer to emit a numeric year of century field.
| |||||||||||
Instructs the printer to emit a numeric yearOfEra field.
| |||||||||||
Returns true if toFormatter can be called without throwing an
UnsupportedOperationException.
| |||||||||||
Returns true if toParser can be called without throwing an
UnsupportedOperationException.
| |||||||||||
Returns true if toPrinter can be called without throwing an
UnsupportedOperationException.
| |||||||||||
Clears out all the appended elements, allowing this builder to be
reused.
| |||||||||||
Constructs a DateTimeFormatter using all the appended elements.
| |||||||||||
Internal method to create a DateTimeParser instance using all the
appended elements.
| |||||||||||
Internal method to create a DateTimePrinter instance using all the
appended elements.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Creates a DateTimeFormatterBuilder.
Appends a printer and a set of matching parsers. When parsing, the first parser in the list is selected for parsing. If it fails, the next is chosen, and so on. If none of these parsers succeeds, then the failed position of the parser that made the greatest progress is returned.
Only the printer is optional. In addtion, it is illegal for any but the last of the parser array elements to be null. If the last element is null, this represents the empty parser. The presence of an empty parser indicates that the entire array of parse formats is optional.
printer | the printer to add |
---|---|
parsers | the parsers to add |
IllegalArgumentException | if any printer or parser is of an invalid type |
---|---|
IllegalArgumentException | if any parser element but the last is null |
Appends a printer/parser pair.
printer | the printer to add |
---|---|
parser | the parser to add |
IllegalArgumentException | if printer or parser is null or of an invalid type |
---|
Appends another formatter.
formatter | the formatter to add |
---|
IllegalArgumentException | if formatter is null or of an invalid type |
---|
Appends just a printer. With no matching parser, a parser cannot be built from this DateTimeFormatterBuilder.
printer | the printer to add |
---|
IllegalArgumentException | if printer is null or of an invalid type |
---|
Appends just a parser. With no matching printer, a printer cannot be built from this builder.
parser | the parser to add |
---|
IllegalArgumentException | if parser is null or of an invalid type |
---|
Instructs the printer to emit a numeric century of era field.
minDigits | minumum number of digits to print |
---|---|
maxDigits | maximum number of digits to parse, or the estimated maximum number of digits to print |
Instructs the printer to emit a numeric clockhourOfDay field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a numeric clockhourOfHalfday field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a numeric dayOfMonth field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a numeric dayOfWeek field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a short locale-specific dayOfWeek text. The parser will accept a long or short dayOfWeek text, case-insensitive.
Instructs the printer to emit a locale-specific dayOfWeek text. The parser will accept a long or short dayOfWeek text, case-insensitive.
Instructs the printer to emit a numeric dayOfYear field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a field value as a decimal number, and the parser to expect an unsigned decimal number.
fieldType | type of field to append |
---|---|
minDigits | minumum number of digits to print |
maxDigits | maximum number of digits to parse, or the estimated maximum number of digits to print |
IllegalArgumentException | if field type is null |
---|
Instructs the printer to emit a locale-specific era text (BC/AD), and the parser to expect it. The parser is case-insensitive.
Instructs the printer to emit a field value as a fixed-width decimal number (smaller numbers will be left-padded with zeros), and the parser to expect an unsigned decimal number with the same fixed width.
fieldType | type of field to append |
---|---|
numDigits | the exact number of digits to parse or print, except if printed value requires more digits |
IllegalArgumentException | if field type is null or if numDigits <= 0 |
---|
Instructs the printer to emit a field value as a fixed-width decimal number (smaller numbers will be left-padded with zeros), and the parser to expect an signed decimal number with the same fixed width.
fieldType | type of field to append |
---|---|
numDigits | the exact number of digits to parse or print, except if printed value requires more digits |
IllegalArgumentException | if field type is null or if numDigits <= 0 |
---|
Instructs the printer to emit a remainder of time as a decimal fraction, sans decimal point. For example, if the field is specified as minuteOfHour and the time is 12:30:45, the value printed is 75. A decimal point is implied, so the fraction is 0.75, or three-quarters of a minute.
fieldType | type of field to append |
---|---|
minDigits | minumum number of digits to print. |
maxDigits | maximum number of digits to print or parse. |
IllegalArgumentException | if field type is null |
---|
minDigits | minumum number of digits to print |
---|---|
maxDigits | maximum number of digits to print or parse |
minDigits | minumum number of digits to print |
---|---|
maxDigits | maximum number of digits to print or parse |
minDigits | minumum number of digits to print |
---|---|
maxDigits | maximum number of digits to print or parse |
minDigits | minumum number of digits to print |
---|---|
maxDigits | maximum number of digits to print or parse |
Instructs the printer to emit a locale-specific AM/PM text, and the parser to expect it. The parser is case-insensitive.
Instructs the printer to emit a numeric hourOfDay field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a numeric hourOfHalfday field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit specific text, and the parser to expect it. The parser is case-insensitive.
IllegalArgumentException | if text is null |
---|
Instructs the printer to emit a specific character, and the parser to expect it. The parser is case-insensitive.
Instructs the printer to emit a numeric millisOfDay field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a numeric millisOfSecond field.
This method will append a field that prints a three digit value.
During parsing the value that is parsed is assumed to be three digits.
If less than three digits are present then they will be counted as the
smallest parts of the millisecond. This is probably not what you want
if you are using the field as a fraction. Instead, a fractional
millisecond should be produced using appendFractionOfSecond(int, int)
.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a numeric minuteOfDay field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a numeric minuteOfHour field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a numeric monthOfYear field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a locale-specific monthOfYear text. The parser will accept a long or short monthOfYear text, case-insensitive.
Instructs the printer to emit a short locale-specific monthOfYear text. The parser will accept a long or short monthOfYear text, case-insensitive.
Appends just a parser element which is optional. With no matching printer, a printer cannot be built from this DateTimeFormatterBuilder.
IllegalArgumentException | if parser is null or of an invalid type |
---|
Calls upon DateTimeFormat
to parse the pattern and append the
results into this builder.
pattern | pattern specification |
---|
IllegalArgumentException | if the pattern is invalid |
---|
Instructs the printer to emit a numeric secondOfDay field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a numeric secondOfMinute field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a field value as short text, and the parser to expect text.
fieldType | type of field to append |
---|
IllegalArgumentException | if field type is null |
---|
Instructs the printer to emit a field value as a decimal number, and the parser to expect a signed decimal number.
fieldType | type of field to append |
---|---|
minDigits | minumum number of digits to print |
maxDigits | maximum number of digits to parse, or the estimated maximum number of digits to print |
IllegalArgumentException | if field type is null |
---|
Instructs the printer to emit a field value as text, and the parser to expect text.
fieldType | type of field to append |
---|
IllegalArgumentException | if field type is null |
---|
Instructs the printer to emit the identifier of the time zone. This field cannot currently be parsed.
Instructs the printer to emit a locale-specific time zone name. A parser cannot be created from this builder if a time zone name is appended.
Instructs the printer to emit text and numbers to display time zone offset from UTC. A parser will use the parsed time zone offset to adjust the datetime.
zeroOffsetText | Text to use if time zone offset is zero. If null, offset is always shown. |
---|---|
showSeparators | If true, prints ':' separator before minute and second field and prints '.' separator before fraction field. |
minFields | minimum number of fields to print, stopping when no more precision is required. 1=hours, 2=minutes, 3=seconds, 4=fraction |
maxFields | maximum number of fields to print |
Instructs the printer to emit a short locale-specific time zone name. A parser cannot be created from this builder if time zone name is appended.
Instructs the printer to emit a numeric weekyear field which always prints
and parses two digits. A pivot year is used during parsing to determine
the range of supported years as (pivot - 50) .. (pivot + 49)
.
pivot supported range 00 is 20 is 40 is 60 is 80 is --------------------------------------------------------------- 1950 1900..1999 1900 1920 1940 1960 1980 1975 1925..2024 2000 2020 1940 1960 1980 2000 1950..2049 2000 2020 2040 1960 1980 2025 1975..2074 2000 2020 2040 2060 1980 2050 2000..2099 2000 2020 2040 2060 2080
pivot | pivot weekyear to use when parsing |
---|
Instructs the printer to emit a numeric weekyear field which always prints
two digits. A pivot year is used during parsing to determine the range
of supported years as (pivot - 50) .. (pivot + 49)
. If
parse is instructed to be lenient and the digit count is not two, it is
treated as an absolute weekyear. With lenient parsing, specifying a positive
or negative sign before the weekyear also makes it absolute.
pivot | pivot weekyear to use when parsing |
---|---|
lenientParse | when true, if digit count is not two, it is treated as an absolute weekyear |
Instructs the printer to emit a numeric year field which always prints
two digits. A pivot year is used during parsing to determine the range
of supported years as (pivot - 50) .. (pivot + 49)
. If
parse is instructed to be lenient and the digit count is not two, it is
treated as an absolute year. With lenient parsing, specifying a positive
or negative sign before the year also makes it absolute.
pivot | pivot year to use when parsing |
---|---|
lenientParse | when true, if digit count is not two, it is treated as an absolute year |
Instructs the printer to emit a numeric year field which always prints
and parses two digits. A pivot year is used during parsing to determine
the range of supported years as (pivot - 50) .. (pivot + 49)
.
pivot supported range 00 is 20 is 40 is 60 is 80 is --------------------------------------------------------------- 1950 1900..1999 1900 1920 1940 1960 1980 1975 1925..2024 2000 2020 1940 1960 1980 2000 1950..2049 2000 2020 2040 1960 1980 2025 1975..2074 2000 2020 2040 2060 1980 2050 2000..2099 2000 2020 2040 2060 2080
pivot | pivot year to use when parsing |
---|
Instructs the printer to emit a numeric weekOfWeekyear field.
minDigits | minumum number of digits to print |
---|
Instructs the printer to emit a numeric weekyear field.
minDigits | minumum number of digits to print |
---|---|
maxDigits | maximum number of digits to parse, or the estimated maximum number of digits to print |
Instructs the printer to emit a numeric year field.
minDigits | minumum number of digits to print |
---|---|
maxDigits | maximum number of digits to parse, or the estimated maximum number of digits to print |
Instructs the printer to emit a numeric year of century field.
minDigits | minumum number of digits to print |
---|---|
maxDigits | maximum number of digits to parse, or the estimated maximum number of digits to print |
Instructs the printer to emit a numeric yearOfEra field.
minDigits | minumum number of digits to print |
---|---|
maxDigits | maximum number of digits to parse, or the estimated maximum number of digits to print |
Returns true if toFormatter can be called without throwing an UnsupportedOperationException.
Returns true if toParser can be called without throwing an UnsupportedOperationException.
Returns true if toPrinter can be called without throwing an UnsupportedOperationException.
Clears out all the appended elements, allowing this builder to be reused.
Constructs a DateTimeFormatter using all the appended elements.
This is the main method used by applications at the end of the build process to create a usable formatter.
Subsequent changes to this builder do not affect the returned formatter.
The returned formatter may not support both printing and parsing.
The methods isPrinter()
and
isParser()
will help you determine the state
of the formatter.
UnsupportedOperationException | if neither printing nor parsing is supported |
---|
Internal method to create a DateTimeParser instance using all the appended elements.
Most applications will not use this method.
If you want a parser in an application, call toFormatter()
and just use the parsing API.
Subsequent changes to this builder do not affect the returned parser.
UnsupportedOperationException | if parsing is not supported |
---|
Internal method to create a DateTimePrinter instance using all the appended elements.
Most applications will not use this method.
If you want a printer in an application, call toFormatter()
and just use the printing API.
Subsequent changes to this builder do not affect the returned printer.
UnsupportedOperationException | if printing is not supported |
---|