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

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

Introduction

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

Prototype

public PeriodFormatterBuilder printZeroIfSupported() 

Source Link

Document

Print zero values for the next and following appended fields only if the period supports it.

Usage

From source file:org.starnub.utilities.time.DateAndTimes.java

License:Open Source License

public static String getPeriodFormattedFromMilliseconds(long duration, boolean printZeros, int digitCount,
        String... separators) {//w  w w .java  2  s .  c  om
    Period period = new Period(duration).normalizedStandard();
    PeriodFormatterBuilder formatterBuilder = new PeriodFormatterBuilder().minimumPrintedDigits(digitCount);
    if (printZeros) {
        formatterBuilder.printZeroIfSupported();
    }
    formatterBuilder.appendYears().appendSeparator(separators[0]).appendMonths().appendSeparator(separators[1])
            .appendWeeks().appendSeparator(separators[2]).appendDays().appendSeparator(separators[3])
            .appendHours().appendSeparator(separators[4]).appendMinutes().appendSeparator(separators[5])
            .appendSeconds().appendLiteral(separators[6]);
    return formatterBuilder.toFormatter().print(period);
}

From source file:org.starnub.utilities.time.DateAndTimes.java

License:Open Source License

public static String getPeriodFormattedFromMillisecondsSuffix(long duration, boolean printZeros, int digitCount,
        String... separators) {/*from ww  w.jav  a 2  s  . co m*/
    Period period = new Period(duration).normalizedStandard();
    PeriodFormatterBuilder formatterBuilder = new PeriodFormatterBuilder().minimumPrintedDigits(digitCount);
    if (printZeros) {
        formatterBuilder.printZeroIfSupported();
    }
    formatterBuilder.appendYears().appendSuffix(separators[0], separators[1]).appendMonths()
            .appendSuffix(separators[2], separators[3]).appendWeeks().appendSuffix(separators[4], separators[5])
            .appendDays().appendSuffix(separators[6], separators[7]).appendHours()
            .appendSuffix(separators[8], separators[9]).appendMinutes()
            .appendSuffix(separators[10], separators[11]).appendSeconds()
            .appendSuffix(separators[12], separators[13]);
    return formatterBuilder.toFormatter().print(period);
}