2011-12-14 50 views
1

我使用PHP解析網站上的一些數據,這讓我的時間在這個格式量:這種「P16DT1H58M47S」是什麼樣的時間格式?

P16DT1H58M47S 

但他們並不總是有天數,像這樣:

PT8H10M3S 

而且時有時無時間:

PT33M57S 

我需要找到的是將其轉換成幾秒鐘的總數的方式。我不需要將它放入日期對象中,但是我希望找到一種相當快速的方法來完成此任務,因爲我需要處理大量數據。

回答

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 
+0

這是它的感謝!我現在正在使用這樣的東西:`echo $ date-> format('%d days%h hours%i minutes%s seconds');` – Vance 2011-12-14 17:57:33