Converting ISO 8601 Duration Time Format in PHP
This little sniplet will enable you to parse ISO 8601 Period (Duration) Time Formats into seconds. The ISO 8601 Period is represented by a string like PnYnMnDTnHnMnS where nY represents the number of years, nM the months, nD the days, nH the hours, nM the Minutes and nS the Seconds. The T seperates the date (to the left of the T) from the time (to the right of the T). Parsing this string is quite tricky, because unneeded values (like years and months for durations shorter than a month) can be left out. Parsing is also tricky, because we face two “M” as identifiers (for months and Minutes).