List of usage examples for org.joda.time.format PeriodFormatterBuilder appendWeeks
public PeriodFormatterBuilder appendWeeks()
From source file:com.mobileman.kuravis.core.util.DateTimeUtils.java
License:Apache License
/** * @param date/* ww w . j av a 2 s . 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.openvpms.archetype.i18n.time.DateDurationFormatter.java
License:Open Source License
/** * Constructs a {@link DateDurationFormatter}. * * @param showYears determines if years should be displayed * @param showMonths determines if months should be displayed * @param showWeeks determines if weeks should be displayed * @param showDays determines if days should be displayed * @param showHours determines if hours should be displayed * @param showMinutes determines if minutes should be displayed *///w ww . ja v a 2s .c o m protected DateDurationFormatter(boolean showYears, boolean showMonths, boolean showWeeks, boolean showDays, boolean showHours, boolean showMinutes) { this.showYears = showYears; this.showMonths = showMonths; this.showWeeks = showWeeks; this.showDays = showDays; this.showHours = showHours; this.showMinutes = showMinutes; PeriodFormatterBuilder builder = new PeriodFormatterBuilder(); if (showYears) { builder = builder.appendYears().appendSuffix(YEAR_SUFFIX, YEARS_SUFFIX).appendSeparator(" "); } if (showMonths) { builder = builder.appendMonths().appendSuffix(MONTH_SUFFIX, MONTHS_SUFFIX).appendSeparator(" "); } if (showWeeks) { builder = builder.appendWeeks().appendSuffix(WEEK_SUFFIX, WEEKS_SUFFIX).appendSeparator(" "); } if (showDays) { builder = builder.appendDays().appendSuffix(DAY_SUFFIX, DAYS_SUFFIX).appendSeparator(" "); } if (showHours) { builder = builder.appendHours().appendSuffix(HOUR_SUFFIX, HOURS_SUFFIX).appendSeparator(" "); } if (showMinutes) { builder = builder.appendMinutes().appendSuffix(MINUTE_SUFFIX, MINUTES_SUFFIX).appendSeparator(" "); } formatter = builder.toFormatter(); }