本文整理汇总了Java中org.joda.time.format.PeriodFormatterBuilder类的典型用法代码示例。如果您正苦于以下问题:Java PeriodFormatterBuilder类的具体用法?Java PeriodFormatterBuilder怎么用?Java PeriodFormatterBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PeriodFormatterBuilder类属于org.joda.time.format包,在下文中一共展示了PeriodFormatterBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatDuration
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
public static String formatDuration(long duration)
{
// Using Joda Time
DateTime now = new DateTime(); // Now
DateTime plus = now.plus(new Duration(duration * 1000));
// Define and calculate the interval of time
Interval interval = new Interval(now.getMillis(), plus.getMillis());
Period period = interval.toPeriod(PeriodType.time());
// Define the period formatter for pretty printing
String ampersand = " & ";
PeriodFormatter pf = new PeriodFormatterBuilder().appendHours().appendSuffix(ds("hour"), ds("hours"))
.appendSeparator(" ", ampersand).appendMinutes().appendSuffix(ds("minute"), ds("minutes"))
.appendSeparator(ampersand).appendSeconds().appendSuffix(ds("second"), ds("seconds")).toFormatter();
return pf.print(period).trim();
}
示例2: prettifyDuration
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
private String prettifyDuration(String duration) {
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendDays().appendSuffix("d")
.appendHours().appendSuffix(":")
.appendMinutes().appendSuffix(":")
.appendSeconds().toFormatter();
Period p = formatter.parsePeriod(duration);
String day = context.getResources().getString(R.string.day_short);
if(p.getDays() > 0) {
return String.format("%d"+ day + " %dh %dm", p.getDays(), p.getHours(), p.getMinutes());
} else if (p.getHours() > 0) {
return String.format(Locale.getDefault(), "%dh %dm", p.getHours(), p.getMinutes());
} else {
return String.format(Locale.getDefault(), "%dm", p.getMinutes());
}
}
示例3: timeStringSmallScale
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
/**
* Internal method to convert a period of lesser than month scales
*
* @param period The period to format
* @return A relative time string describing the period
*/
private String timeStringSmallScale(Period period) {
PeriodFormatterBuilder builder = new PeriodFormatterBuilder()
.printZeroNever()
.appendDays()
.appendSuffix(" ")
.appendSuffix(i18n.getString(TIMEUNIT_DAY), i18n.getString(TIMEUNIT_DAYS))
.appendSeparator(", ")
.appendHours()
.appendSuffix(" ")
.appendSuffix(i18n.getString(TIMEUNIT_HOUR), i18n.getString(TIMEUNIT_HOURS))
.appendSeparator(", ")
.appendMinutes()
.appendSuffix(" ")
.appendSuffix(i18n.getString(TIMEUNIT_MINUTE), i18n.getString(TIMEUNIT_MINUTES));
if (period.toStandardHours().getHours() == 0) {
// Do not append seconds if the period is larger than one hour
builder.appendSeparator(", ")
.appendSeconds()
.appendSuffix(" ")
.appendSuffix(i18n.getString(TIMEUNIT_SECOND), i18n.getString(TIMEUNIT_SECONDS));
}
return builder.toFormatter().print(period);
}
示例4: timeStringLargeScale
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
/**
* Internal method to convert a period of greater than month scales
*
* @param period The period to format
* @return A relative time string describing the period
*/
private String timeStringLargeScale(Period period) {
return new PeriodFormatterBuilder()
.printZeroNever()
.appendYears()
.appendSuffix(" ")
.appendSuffix(i18n.getString(TIMEUNIT_YEAR), i18n.getString(TIMEUNIT_YEARS))
.appendSeparator(", ")
.appendMonths()
.appendSuffix(" ")
.appendSuffix(i18n.getString(TIMEUNIT_MONTH), i18n.getString(TIMEUNIT_MONTHS))
.appendSeparator(", ")
.appendDays()
.appendSuffix(" ")
.appendSuffix(i18n.getString(TIMEUNIT_DAY), i18n.getString(TIMEUNIT_DAYS))
.toFormatter()
.print(period);
}
示例5: TimestampPickerController
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
@VisibleForTesting
public TimestampPickerController(Locale locale, boolean isStartCrop, String negativePrefix,
String hourMinuteDivider, String minuteSecondDivider,
OnTimestampErrorListener errorListener) {
mLocale = locale;
mIsStartCrop = isStartCrop;
mErrorListener = errorListener;
mNegativePrefix = negativePrefix;
// Builds the formatter, which will be used to read and write timestamp strings.
mPeriodFormatter = new PeriodFormatterBuilder()
.rejectSignedValues(true) // Applies to all fields
.printZeroAlways() // Applies to all fields
.appendHours()
.appendLiteral(hourMinuteDivider)
.minimumPrintedDigits(2) // Applies to minutes and seconds
.appendMinutes()
.appendLiteral(minuteSecondDivider)
.appendSecondsWithMillis()
.toFormatter()
.withLocale(mLocale);
}
示例6: calculateAge
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
private static String calculateAge(DateTime epDate) {
Period period;
if (epDate.isBefore(new DateTime())) {
period = new Period(epDate, new DateTime());
} else {
period = new Period(new DateTime(), epDate);
}
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendYears().appendSuffix("y")
.appendMonths().appendSuffix("m")
.appendWeeks().appendSuffix("w")
.appendDays().appendSuffix("d ")
.appendHours().appendSuffix("h")
.appendMinutes().appendSuffix("m")
.printZeroNever().toFormatter();
return formatter.print(period);
}
示例7: dateHelper
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
private Helper<Long> dateHelper() {
return new Helper<Long>() {
public CharSequence apply(Long arg0, Options arg1) throws IOException {
PeriodFormatter formatter = new PeriodFormatterBuilder()
.appendDays()
.appendSuffix(" d : ")
.appendHours()
.appendSuffix(" h : ")
.appendMinutes()
.appendSuffix(" m : ")
.appendSeconds()
.appendSuffix(" s : ")
.appendMillis()
.appendSuffix(" ms")
.toFormatter();
return formatter.print(new Period((arg0 * 1) / 1000000));
}
};
}
示例8: VanitygenPanel
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
public VanitygenPanel() {
super(MessageKey.vanity_address, AwesomeIcon.VIMEO_SQUARE);
passwordGetter = new PasswordPanel.PasswordGetter(VanitygenPanel.this);
remainingTimeFormatter = new PeriodFormatterBuilder().printZeroNever().appendYears().appendSuffix
(LocaliserUtils.getString("vanity_time_year_suffix")).appendMonths().appendSuffix
(LocaliserUtils.getString("vanity_time_month_suffix")).appendDays().appendSuffix
(LocaliserUtils.getString("vanity_time_day_suffix")).appendHours().appendSuffix
(LocaliserUtils.getString("vanity_time_hour_suffix")).appendMinutes()
.appendSuffix(LocaliserUtils.getString("vanity_time_minute_suffix"))
.appendSeconds().appendSuffix(LocaliserUtils.getString
("vanity_time_second_suffix")).toFormatter();
setOkAction(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (isInCalculatingView) {
generateAddress();
} else {
showCalculate();
}
}
});
if (OSUtils.isWindows() && SystemUtil.isSystem32()) {
ecKeyType = BitherSetting.ECKeyType.UNCompressed;
}
}
示例9: formattedDuration
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
public static String formattedDuration(long duration) {
PeriodFormatter hoursMinutes = new PeriodFormatterBuilder()
.appendHours()
.appendSuffix(" hr", " hrs")
.appendSeparator(" ")
.appendMinutes()
.appendSuffix(" min", " mins")
.appendSeparator(" ")
.appendSeconds()
.appendSuffix(" sec", " secs")
.toFormatter();
Period p = new Period(duration);
return hoursMinutes.print(p);
}
示例10: getGatewayDeploymentsBackupAgeLimit
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
public long getGatewayDeploymentsBackupAgeLimit() {
PeriodFormatter f = (new PeriodFormatterBuilder()).appendDays().toFormatter();
String s = this.get("gateway.deployment.backup.ageLimit", "-1");
long d;
try {
Period e = Period.parse(s, f);
d = e.toStandardDuration().getMillis();
if (d < 0L) {
d = -1L;
}
} catch (Exception var6) {
d = -1L;
}
return d;
}
示例11: JodaFormatter
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
/**
* Default constructor.
*/
public JodaFormatter() {
PeriodFormatterBuilder periodFormatterBuilder = new PeriodFormatterBuilder().appendYears().appendSuffix(" year", " years")
.appendMonths().appendSuffix(" month", " months")
.appendWeeks().appendSuffix(" week", " weeks")
.appendDays().appendSuffix(" day", " days")
.appendHours().appendSuffix(" hour", " hours")
.appendMinutes().appendSuffix(" minute", " minutes")
.appendSeconds().appendSuffix(" second", " seconds");
periodParser = periodFormatterBuilder.toParser();
periodFormatter = periodFormatterBuilder.toFormatter();
dateTimeFormatter = ISODateTimeFormat.dateTime();
}
示例12: periodHourMinBased
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
public static String periodHourMinBased(long secDuration) {
PeriodFormatterBuilder builder = new PeriodFormatterBuilder();
PeriodFormatter formatter = null;
String minutesAbbr = ToggApp.getApplication().getString(
R.string.minutes_abbr);
;
String hoursAbbr = ToggApp.getApplication().getString(
R.string.hours_abbr);
;
formatter = builder.printZeroAlways().minimumPrintedDigits(1)
.appendHours().appendLiteral(" " + hoursAbbr + " ")
.minimumPrintedDigits(2).appendMinutes()
.appendLiteral(" " + minutesAbbr).toFormatter();
Period period = new Period(secDuration * 1000);
return formatter.print(period.normalizedStandard());
}
示例13: providePeriodFormatter
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
@Singleton
@Provides
public PeriodFormatter providePeriodFormatter(Dictionary<String> dictionary) {
return new PeriodFormatterBuilder()
.appendYears()
.appendSuffix(" " + dictionary.getTranslation("year"), " " + dictionary.getTranslation("years"))
.appendSeparator(" ")
.appendMonths()
.appendSuffix(" " + dictionary.getTranslation("month"), " " + dictionary.getTranslation("months"))
.appendSeparator(" ")
.appendDays()
.appendSuffix(" " + dictionary.getTranslation("day"), " " + dictionary.getTranslation("days"))
.appendSeparator(" ")
.appendMinutes()
.appendSuffix(" " + dictionary.getTranslation("minute"), " " + dictionary.getTranslation("minutes"))
.appendSeparator(" ")
.appendSeconds()
.appendSuffix(" " + dictionary.getTranslation("second"), " " + dictionary.getTranslation("seconds"))
.toFormatter();
}
示例14: postFailureBuild
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
private void postFailureBuild(SRunningBuild build )
{
String message = "";
PeriodFormatter durationFormatter = new PeriodFormatterBuilder()
.printZeroRarelyFirst()
.appendHours()
.appendSuffix(" hour", " hours")
.appendSeparator(" ")
.printZeroRarelyLast()
.appendMinutes()
.appendSuffix(" minute", " minutes")
.appendSeparator(" and ")
.appendSeconds()
.appendSuffix(" second", " seconds")
.toFormatter();
Duration buildDuration = new Duration(1000*build.getDuration());
message = String.format("Project '%s' build failed! ( %s )" , build.getFullName() , durationFormatter.print(buildDuration.toPeriod()));
postToSlack(build, message, false);
}
示例15: processSuccessfulBuild
import org.joda.time.format.PeriodFormatterBuilder; //导入依赖的package包/类
private void processSuccessfulBuild(SRunningBuild build) {
String message = "";
PeriodFormatter durationFormatter = new PeriodFormatterBuilder()
.printZeroRarelyFirst()
.appendHours()
.appendSuffix(" hour", " hours")
.appendSeparator(" ")
.printZeroRarelyLast()
.appendMinutes()
.appendSuffix(" minute", " minutes")
.appendSeparator(" and ")
.appendSeconds()
.appendSuffix(" second", " seconds")
.toFormatter();
Duration buildDuration = new Duration(1000*build.getDuration());
message = String.format("Project '%s' built successfully in %s." , build.getFullName() , durationFormatter.print(buildDuration.toPeriod()));
postToSlack(build, message, true);
}