Java DurationFormatUtils.formatDurationISO() Function Last Updated : 28 Dec, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The DurationFormatUtils class provides a convenient way to format durations in a human-readable format. The formatDurationISO() function is a part of this class & allows you to format durations in the ISO-8601 duration format. This format represents durations using the PnYnMnDTnHnMnS pattern. where P indicates the period & T separates the date & time components. Note: you need to add the org.apache.commons.lang3 library to your project Syntax of formatDurationISO() Function:public static String formatDurationISO(long durationMillis)Example of Java formatDurationISO() FunctionExample 1 :The formatDurationISO() function takes a duration in the milliseconds as input & returns a formatted string representation of the duration in the ISO-8601 format. Java // Java program to convert time into ISO format import java.io.*; import org.apache.commons.lang3.time.DurationFormatUtils; //Driver Class public class GFG { //Main method public static void main(String[] args) { // Define the duration in milliseconds long durationMillis = 3600000; // Convert the duration to a human-readable ISO format using DurationFormatUtils String formattedDuration = DurationFormatUtils.formatDurationISO(durationMillis); // Print the formatted duration with a descriptive message System.out.println("Formatted Duration: " + formattedDuration); } } Output:Formatted Duration: PT1HExplanation of the above Program: The formatDurationISO() function formats the duration of 1 hour (3600000 milliseconds) into ISO-8601 duration format "PT1H", indicating 1 hour. Example 2:The formatDurationISO() function takes a duration in the milliseconds as input & returns a formatted string representation of the duration in the ISO-8601 format. Java // Java program to convert time into ISO-8601 duration // format import java.io.*; import org.apache.commons.lang3.time.DurationFormatUtils; // Driver class public class GFG { // Main method public static void main(String[] args) { // Define the duration in milliseconds long durationMillis = 86400000; // Convert the duration to a human-readable format // using DurationFormatUtils String formattedDuration = DurationFormatUtils.formatDurationISO(durationMillis); // Print the formatted duration System.out.println("Formatted Duration: " + formattedDuration); } } Output:Formatted Duration: P1DExplanation of the above Program: The formatDurationISO() function formats the duration of the 1 day (86400000 milliseconds) into ISO-8601 duration format "P1D", indicating 1 day. Comment More infoAdvertise with us Next Article DateFormat getDateTimeInstance() Method in Java with Examples S subramanyasmgm Follow Improve Article Tags : Java Java-Duration Practice Tags : Java Similar Reads DateFormat format() Method in Java with Examples DateFormat class present inside java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. DateFormat class extend 2 min read DateFormat getDateInstance() Method in Java with Examples DateFormat class of java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. Note: DateFormat class extends Form 2 min read DateFormat format(Date obj) method in Java The format() method of DateFormat class in Java is used to format a given Date object into a string representing Date/Time.Syntax: String format(Date date) Parameters: This method accepts a single parameter date which is a Date object. Return Value: This method returns a String which is the formatte 2 min read Duration getUnits() method in Java with Examples The getUnits() method of Duration Class in java.time package is used to get the list of units that are supported by this duration. Syntax: public List<TemporalUnit> getUnits() Parameters: This method do not accepts any parameter. Return Value: This method returns a list of units that are suppo 1 min read DateFormat getDateTimeInstance() Method in Java with Examples DateFormat class of java.text package is an abstract class that is used to format and parse dates for any locale. It allows us to format date to text and parse text to date. DateFormat class provides many functionalities to obtain, format, parse default date/time. Note: DateFormat class extends Form 2 min read ChronoUnit getDuration() method in Java with Examples The getDuration() method of ChronoUnit enum is used to return the estimated duration of this ChronoUnit in the ISO calendar system.Days vary due to daylight saving time, while months have different lengths. Syntax: public Duration getDuration() Parameters: This method accepts nothing. Return value: 1 min read Like