List of usage examples for org.joda.time.format PeriodFormatterBuilder appendSeconds
public PeriodFormatterBuilder appendSeconds()
From source file:com.mobileman.kuravis.core.util.DateTimeUtils.java
License:Apache License
/** * @param date// w w w . ja v a 2s. c o m * @return formatted elapsed time from now */ public static String fmtElapsedTime(Date date) { if (date == null) { return ""; } Period period = new Period(date.getTime(), Calendar.getInstance().getTimeInMillis()); PeriodFormatterBuilder pf = new PeriodFormatterBuilder(); pf.appendPrefix(" vor "); if (period.getYears() > 0) { pf.appendYears().appendSuffix(" Jahr", " Jahren"); } else if (period.getMonths() > 0) { pf.appendMonths().appendSuffix(" Monat", " Monaten"); } else if (period.getWeeks() > 0) { pf.appendWeeks().appendSuffix(" Woche ", " Wochen"); } else if (period.getDays() > 0) { pf.appendDays().appendSuffix(" Tag ", " Tagen"); } else if (period.getHours() > 0) { pf.appendHours().appendSuffix(" Stunde ", " Stunden"); } else if (period.getMinutes() > 0) { pf.appendMinutes().appendSuffix(" Minute ", " Minuten"); } else if (period.getSeconds() > 0) { pf.appendSeconds().appendSuffix(" Sekunde ", " Sekunden"); } return pf.toFormatter().print(period); }
From source file:org.jspresso.framework.util.format.DurationFormatter.java
License:Open Source License
/** * Constructs a new {@code DurationFormatter} instance. * * @param translationProvider//from w w w .ja v a 2 s .co m * 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); }