本文整理汇总了Java中org.joda.time.format.PeriodFormatter.print方法的典型用法代码示例。如果您正苦于以下问题:Java PeriodFormatter.print方法的具体用法?Java PeriodFormatter.print怎么用?Java PeriodFormatter.print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.format.PeriodFormatter
的用法示例。
在下文中一共展示了PeriodFormatter.print方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateAge
import org.joda.time.format.PeriodFormatter; //导入方法依赖的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);
}
示例2: dateHelper
import org.joda.time.format.PeriodFormatter; //导入方法依赖的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));
}
};
}
示例3: formattedDuration
import org.joda.time.format.PeriodFormatter; //导入方法依赖的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);
}
示例4: periodHourMinBased
import org.joda.time.format.PeriodFormatter; //导入方法依赖的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());
}
示例5: toAge
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
public static String toAge(Date from, Date to) {
if (from == null || to == null) return "N/A";
final Period period = new Period(from.getTime(), to.getTime());
DurationFieldType[] dtf = new ArrayList<DurationFieldType>() {{
add(DurationFieldType.years()); add(DurationFieldType.months());
add(DurationFieldType.days());
if (period.getYears() == 0 && period.getMonths() == 0 && period.getDays() == 0) {
add(DurationFieldType.hours());
add(DurationFieldType.minutes());
}
}}.toArray(new DurationFieldType[0]);
PeriodFormatter pf = PeriodFormat.getDefault();
return pf.print(period.normalizedStandard(PeriodType.forFields(dtf)));
}
示例6: success
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
@Override
public void success()
{
jobExecution.setEndDate(Instant.now());
jobExecution.setStatus(SUCCESS);
jobExecution.setProgressInt(jobExecution.getProgressMax());
Duration yourDuration = Duration.millis(timeRunning());
Period period = yourDuration.toPeriod();
PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendDays()
.appendSuffix("d ")
.appendHours()
.appendSuffix("h ")
.appendMinutes()
.appendSuffix("m ")
.appendSeconds()
.appendSuffix("s ")
.appendMillis()
.appendSuffix("ms ")
.toFormatter();
String timeSpent = periodFormatter.print(period);
JOB_EXECUTION_LOG.info("Execution successful. Time spent: {}", timeSpent);
sendEmail(jobExecution.getSuccessEmail(), jobExecution.getType() + " job succeeded.", jobExecution.getLog());
update();
JobExecutionContext.unset();
}
示例7: getDiffFormatted
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
public static String getDiffFormatted(Date from, Date to) {
Duration duration = new Duration(to.getTime() - from.getTime()); // in
// milliseconds
PeriodFormatter formatter = new PeriodFormatterBuilder().printZeroNever()//
.appendWeeks().appendSuffix("w").appendSeparator(" ")//
.appendDays().appendSuffix("d").appendSeparator(" ")//
.appendHours().appendSuffix("h").appendSeparator(" ")//
.appendMinutes().appendSuffix("m").appendSeparator(" ")//
.appendSeconds().appendSuffix("s")//
.toFormatter();
String fullTimeAgo = formatter.print(duration.toPeriod(PeriodType.yearMonthDayTime()));
return Arrays.stream(fullTimeAgo.split(" ")).limit(2).collect(Collectors.joining(" "));
}
示例8: convertMillisecondToMinutesAndSecond
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
public static String convertMillisecondToMinutesAndSecond(long milliseconds) {
Duration duration = new Duration(milliseconds);
Period period = duration.toPeriod();
PeriodFormatter minutesAndSeconds = new PeriodFormatterBuilder()
.printZeroAlways()
.appendMinutes()
.appendSeparator(":")
.appendSeconds()
.toFormatter();
return minutesAndSeconds.print(period);
}
示例9: getTimestamp
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
public static String getTimestamp(long duration) {
PeriodFormatter periodFormatter = new PeriodFormatterBuilder()
.appendYears().appendSuffix("y ")
.appendMonths().appendSuffix("m ")
.appendWeeks().appendSuffix("w ")
.appendDays().appendSuffix("d ")
.appendHours().appendSuffix("h ")
.appendMinutes().appendSuffix("m ")
.appendSeconds().appendSuffix("s")
.toFormatter();
return periodFormatter.print(new Period(new Duration(duration)).normalizedStandard());
}
示例10: timeToString
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
/**
* Generic method to convert the milliseconds into the elapsed time string.
*
* @param start Start timestamp.
* @param finish End timestamp.
* @return String representation of the elapsed time.
*/
public static String timeToString(long start, long finish) {
Duration duration = new Duration(finish - start); // in milliseconds
PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix("d")
.appendHours().appendSuffix("h").appendMinutes().appendSuffix("m").appendSeconds()
.appendSuffix("s").appendMillis().appendSuffix("ms").toFormatter();
return formatter.print(duration.toPeriod());
}
示例11: getFormattedDuration
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
private String getFormattedDuration(int seconds) {
Period period = new Period(Seconds.seconds(seconds));
PeriodFormatter periodFormatter = new PeriodFormatterBuilder()
.printZeroAlways()
.minimumPrintedDigits(2)
.appendHours()
.appendSeparator(":")
.appendMinutes()
.appendSeparator(":")
.appendSeconds()
.toFormatter();
return periodFormatter.print(period.normalizedStandard());
}
示例12: formatPeriod
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
/**
*
* @param start
* Set the start date
* @param end
* Set the end date
* @return a formatted period
*/
public static String formatPeriod(Date start, Date end) {
DateTime startDate = new DateTime(start);
DateTime endDate = new DateTime(end);
Period period = new Interval(startDate, endDate).toPeriod();
PeriodFormatter formatter = new PeriodFormatterBuilder()
.minimumPrintedDigits(2).appendHours().appendSeparator(":")
.appendMinutes().appendSeparator(":").appendSeconds()
.toFormatter();
return formatter.print(period);
}
示例13: calcTimeLaps
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
private String calcTimeLaps(long msLeft) {
Period period = new Period(msLeft);
PeriodFormatter daysHoursMinutes = new PeriodFormatterBuilder()
.appendYears()
.appendSuffix(" year", " years")
.appendSeparator(", ")
.appendMonths()
.appendSuffix(" month", " months")
.appendSeparator(", ")
.appendWeeks()
.appendSuffix(" week", " weeks")
.appendSeparator(", ")
.appendDays()
.appendSuffix(" day", " days")
.appendSeparator(" and ")
.appendHours()
.appendSuffix(" hour", " hours")
.appendSeparator(", ")
.appendMinutes()
.appendSuffix(" minute", " minutes")
.appendSeparator(", ")
.appendSeconds()
.appendSuffix(" second", " seconds")
.appendSeparator(", ")
.appendMillis()
.appendSuffix(" millisecond", " milliseconds")
.toFormatter();
String ret = daysHoursMinutes.print(period.normalizedStandard());
return ret;
}
示例14: toString
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
@Override
public String toString() {
PeriodFormatter formatter = new PeriodFormatterBuilder().appendHours().appendSuffix(":").appendMinutes()
.appendSuffix(":").appendSeconds().appendSuffix(".").appendMillis().toFormatter();
return this.modelName + " duration: " + formatter.print(this.getDuration().toPeriod());
}
示例15: duration
import org.joda.time.format.PeriodFormatter; //导入方法依赖的package包/类
private static String duration(Duration flightDuration) {
Period period = flightDuration.toPeriod();
PeriodFormatter hms = new PeriodFormatterBuilder().appendHours().appendSeparator(":").printZeroAlways()
.appendMinutes().appendSeparator(":").appendSecondsWithMillis().toFormatter();
return hms.print(period);
}