什么样的时间格式是这个" P16DT1H58M47S"?

时间:2011-12-14 17:40:28

标签: php datetime-format time-format

我正在使用PHP解析网站上的一些数据,它给了我这种格式的时间:

P16DT1H58M47S

但他们并不总是有这么多天,如下:

PT8H10M3S

有时候没有时间:

PT33M57S

我需要找到的是将其转换为总秒数的方法。我不需要将它放入日期对象中,但我想找到一种相当快速的方法,因为我有大量的数据需要通过。

1 个答案:

答案 0 :(得分:5)

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
相关问题