本文整理匯總了Java中org.joda.time.format.PeriodFormatterBuilder.appendDays方法的典型用法代碼示例。如果您正苦於以下問題:Java PeriodFormatterBuilder.appendDays方法的具體用法?Java PeriodFormatterBuilder.appendDays怎麽用?Java PeriodFormatterBuilder.appendDays使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.format.PeriodFormatterBuilder
的用法示例。
在下文中一共展示了PeriodFormatterBuilder.appendDays方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: DurationFormatter
import org.joda.time.format.PeriodFormatterBuilder; //導入方法依賴的package包/類
/**
* Constructs a new {@code DurationFormatter} instance.
*
* @param translationProvider
* the translation provider for duration labels.
* @param locale
* the locale the formatter must be constructed in.
*/
public DurationFormatter(ITranslationProvider translationProvider,
Locale locale, boolean secondsAware, boolean millisecondsAware) {
super();
PeriodFormatterBuilder builder = new PeriodFormatterBuilder();
builder.appendDays();
builder.appendSuffix(
" " + translationProvider.getTranslation("day", locale), " "
+ translationProvider.getTranslation("days", locale));
builder.appendSeparator(" ");
builder.appendHours();
builder.appendSuffix(
" " + translationProvider.getTranslation("hour", locale), " "
+ translationProvider.getTranslation("hours", locale));
builder.appendSeparator(" ");
builder.appendMinutes();
builder.appendSuffix(
" " + translationProvider.getTranslation("minute", locale), " "
+ translationProvider.getTranslation("minutes", locale));
if (secondsAware) {
builder.appendSeconds();
builder.appendSuffix(" " + translationProvider.getTranslation("second", locale),
" " + translationProvider.getTranslation("seconds", locale));
}
if (millisecondsAware) {
builder.appendMillis();
builder.appendSuffix(" " + translationProvider.getTranslation("millisecond", locale),
" " + translationProvider.getTranslation("milliseconds", locale));
}
this.formatter = builder.toFormatter().withLocale(locale);
}
示例2: cretePeriodFormatter
import org.joda.time.format.PeriodFormatterBuilder; //導入方法依賴的package包/類
private static PeriodFormatter cretePeriodFormatter(IntervalField startField, IntervalField endField)
{
if (endField == null) {
endField = startField;
}
List<PeriodParser> parsers = new ArrayList<>();
PeriodFormatterBuilder builder = new PeriodFormatterBuilder();
//CHECKSTYLE.OFF
switch (startField) {
case YEAR:
builder.appendYears();
parsers.add(builder.toParser());
if (endField == IntervalField.YEAR) {
break;
}
builder.appendLiteral("-");
case MONTH:
builder.appendMonths();
parsers.add(builder.toParser());
if (endField != IntervalField.MONTH) {
throw new IllegalArgumentException("Invalid interval qualifier: " + startField + " to " + endField);
}
break;
case DAY:
builder.appendDays();
parsers.add(builder.toParser());
if (endField == IntervalField.DAY) {
break;
}
builder.appendLiteral(" ");
case HOUR:
builder.appendHours();
parsers.add(builder.toParser());
if (endField == IntervalField.HOUR) {
break;
}
builder.appendLiteral(":");
case MINUTE:
builder.appendMinutes();
parsers.add(builder.toParser());
if (endField == IntervalField.MINUTE) {
break;
}
builder.appendLiteral(":");
case SECOND:
builder.appendSecondsWithOptionalMillis();
parsers.add(builder.toParser());
}
//CHECKSTYLE.ON
return new PeriodFormatter(builder.toPrinter(), new OrderedPeriodParser(parsers));
}