本文整理汇总了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));
}