Reputation: 75
I am parsing some data on a website using PHP and it gives me the amount of time in this format:
P16DT1H58M47S
But they don't always have the number of days, like so:
PT8H10M3S
And sometimes no hours:
PT33M57S
What I need to find is a way to convert that to a total number of seconds. I do NOT need to put that into a date object, but I would like to find a fairly quick way to do this as I have a lot of data to go through.
Upvotes: 1
Views: 84
Reputation: 47321
http://www.php.net/manual/en/dateinterval.construct.php
Interval specification. The format starts with the letter P, for "period." Each duration period is represented by an integer value followed by a period designator. If the duration contains time elements, that portion of the specification is preceded by the letter T. -------------- Y years M months D days W weeks. These get converted into days, so can not be combined with D. H hours M minutes S seconds
P16DT1H58M47S = 16 days, 1 hour, 58 minute and 47 seconds
Upvotes: 5