Example usage for org.joda.time.format PeriodFormatter withLocale

List of usage examples for org.joda.time.format PeriodFormatter withLocale

Introduction

In this page you can find the example usage for org.joda.time.format PeriodFormatter withLocale.

Prototype

public PeriodFormatter withLocale(Locale locale) 

Source Link

Document

Returns a new formatter with a different locale that will be used for printing and parsing.

Usage

From source file:org.ddialliance.ddiftp.util.Translator.java

License:Open Source License

/**
 * Creates a ISO8601 duration of the form PyYmMwWdDThHmMsS
 * //from   w  w  w  .  j a v  a  2s . c o  m
 * @param start
 * @param end
 * @return ISO8601 duration
 * @throws DDIFtpException
 */
public static String formatIso8601Duration(long start, long end) throws DDIFtpException {
    DateTime startTime = new DateTime(start);
    DateTime endTime = new DateTime(end);
    DurationFieldType[] types = { DurationFieldType.years(), DurationFieldType.months(),
            DurationFieldType.days(), DurationFieldType.hours(), DurationFieldType.minutes(),
            DurationFieldType.seconds() };
    PeriodType periodType = PeriodType.forFields(types);

    try {
        Period period = new Interval(startTime, endTime).toPeriod(periodType);
        PeriodFormatter isoPeriodFormat = ISOPeriodFormat.standard();
        isoPeriodFormat.withLocale(getLocale());
        return period.toString(isoPeriodFormat);
    } catch (Exception e) {
        throw new DDIFtpException("translate.period.intevalerror", new Object[] { start, end }, e);
    }
}