Class PeriodAndDuration

  • All Implemented Interfaces:
    TemporalAmount

    public final class PeriodAndDuration
    extends Object
    implements TemporalAmount
    The combination of a Period and a Duration.

    This allows the representation of ISO 8601 "durations", which comprise a nominal duration (Java Period, i.e., years, months, days), and an accurate duration (Java Duration, i.e., hours, minutes, seconds).

    Since:
    11.1
    • Method Detail

      • parse

        public static PeriodAndDuration parse​(String text)
        Obtains a PeriodAndDuration from a text string.

        This will parse the string based on the ISO-8601 period format PnYnMnDTnHnMnS. A leading minus sign, and negative values for the units, are allowed.

        Parameters:
        text - the text to parse, not null
        Returns:
        the period and duration (never null)
        Throws:
        DateTimeParseException - if the text cannot be parsed to a period and duration
        See Also:
        toString()
      • parseInt

        protected static int parseInt​(String string,
                                      String text,
                                      String errorText)
      • parseNumber

        protected static long parseNumber​(String string,
                                          int multiplier,
                                          String text,
                                          String errorText)
      • parseFraction

        protected static int parseFraction​(String string,
                                           int sign,
                                           String text)
      • toString

        public String toString()
        Outputs this period and duration as a String, such as P6Y3M1DT4H12M5.636224S.

        The output will be in the ISO-8601 period format. A zero period will be represented as zero seconds, "PT0S".

        Overrides:
        toString in class Object
        Returns:
        a string representation of this period, not null
        See Also:
        parse(java.lang.String)