Java Duration Parse parseDuration(final Duration duration)

Here you can find the source of parseDuration(final Duration duration)

Description

parse Duration

License

Open Source License

Declaration

public static String parseDuration(final Duration duration) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.Duration;

public class Main {
    public static String parseDuration(final Duration duration) {
        return parseTimeString(duration.toString());
    }// www . java  2  s. co  m

    public static String parseTimeString(final String timestring) {
        String ts = timestring.substring(2);
        if (ts.contains("S"))
            ts = ts.substring(0, ts.indexOf("S"));
        if (ts.contains("H"))
            ts = ts.replace("H", ":");
        else
            ts = "0:" + ts;
        if (ts.contains("M"))
            ts = ts.replace("M", ":");
        else
            ts = ts.substring(0, ts.indexOf(":") + 1) + "0:" + ts.substring(ts.indexOf(":") + 1);
        return ts;
    }
}

Related

  1. parseDuration(String datePattern)
  2. parseDurationString(String time)