Java Duration Calculate getDurationAsISO8601(Duration duration)

Here you can find the source of getDurationAsISO8601(Duration duration)

Description

Returns a ISO 8601 HH:mm:ss.SSS formated string of a Duration object

License

MIT License

Parameter

Parameter Description
duration A Duration object

Return

The formated string in HH:mm:ss.SSS format

Declaration

public static String getDurationAsISO8601(Duration duration) 

Method Source Code

//package com.java2s;
/**/*  w w  w. j a  va  2s.  co m*/
 * Created by H?kon ?deg?rd L?vdal (hakloev) on 29/04/15.
 * <p>
 * okse is licenced under the MIT licence.
 */

import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.Date;
import java.util.Locale;

import java.util.TimeZone;

public class Main {
    /**
     * Returns a ISO 8601 HH:mm:ss.SSS formated string of a Duration object
     *
     * @param duration A Duration object
     * @return The formated string in HH:mm:ss.SSS format
     */
    public static String getDurationAsISO8601(Duration duration) {
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault());
        long millis = duration.toMillis();
        return format.format(new Date(millis - TimeZone.getDefault().getRawOffset()));
    }
}

Related

  1. daysRoundingUp(Duration duration)
  2. delayedFuture(Duration delay, ScheduledExecutorService executorService)
  3. durationFromNow(TemporalAmount duration)
  4. failAfter(Duration duration)
  5. futureWithTimeout(Duration timeout, ScheduledExecutorService executorService)
  6. getDurationByTimeValues(final long hours, final long minutes, final long seconds)
  7. getExpirationMillis(long now, Duration duration)
  8. getOrThrow(final ListenableFuture Future, final Duration timeout)
  9. getTTLSeconds(Duration duration)