List of usage examples for org.joda.time.format PeriodFormatter withLocale
public PeriodFormatter withLocale(Locale locale)
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); } }