Here you can find the source of getDurationAsISO8601(Duration duration)
Parameter | Description |
---|---|
duration | A Duration object |
public static String getDurationAsISO8601(Duration duration)
//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())); } }