慕娘9325324
Actually if go on Duration API developed in Java @since 1.8 , they have gone with standard ISO 8601with java doc as below :/** * Applies an ISO 8601 Duration to a {@link ZonedDateTime}. * * <p>Since the JDK defined different types for the different parts of a Duration * specification, this utility method is needed when a full Duration is to be applied to a * {@link ZonedDateTime}. See {@link Period} and {@link Duration}. * * <p>All date-based parts of a Duration specification (Year, Month, Day or Week) are parsed * using {@link Period#parse(CharSequence)} and added to the time. The remaining parts (Hour, * Minute, Second) are parsed using {@link Duration#parse(CharSequence)} and added to the time. * * @param time A zoned date time to apply the offset to * @param offset The offset in ISO 8601 Duration format * @return A zoned date time with the offset applied */public static ZonedDateTime addOffset(ZonedDateTime time, String offset) { }Obtains a Duration from a text string of pattern: PnDTnHnMn.nS, wherenD = number of days,nH = number of hours,nM = number of minutes,n.nS = number of seconds, the decimal point may be either a dot or a comma.T = must be used before the part consisting of nH, nM, n.nSExample of implementation with java as import java.time.Duration;public class ParseExample { public static void main(String... args) { parse("PT20S");//T must be at the beginning to time part parse("P2D");//2 day parse("-P2D");//minus 2 days parse("P-2DT-20S");//S for seconds parse("PT20H");//H for hours parse("PT220H"); parse("PT20M");//M for minutes parse("PT20.3S");//second can be in fraction like 20.3 parse("P4DT12H20M20.3S"); parse("P-4DT-12H-20M-20.3S"); parse("-P4DT12H20M20.3S"); } private static void parse(String pattern) { Duration d = Duration.parse(pattern); System.out.println("Pattern: %s => %s%n", pattern, d); }}