Example usage for org.joda.time.format PeriodFormatterBuilder appendPrefix

List of usage examples for org.joda.time.format PeriodFormatterBuilder appendPrefix

Introduction

In this page you can find the example usage for org.joda.time.format PeriodFormatterBuilder appendPrefix.

Prototype

private PeriodFormatterBuilder appendPrefix(PeriodFieldAffix prefix) 

Source Link

Document

Append a field prefix which applies only to the next appended field.

Usage

From source file:com.mobileman.kuravis.core.util.DateTimeUtils.java

License:Apache License

/**
 * @param date/*  w  ww.  j  a v a 2 s .com*/
 * @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);
}