“P16DT1H58M47S”是什么类型的时间格式?

发布于 2024-12-21 08:43:05 字数 270 浏览 5 评论 0原文

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

P16DT1H58M47S

但它们并不总是有天数,像这样:

PT8H10M3S

有时没有小时数:

PT33M57S

我需要找到一种方法将其转换为总秒数。我不需要将其放入日期对象中,但我想找到一种相当快速的方法来执行此操作,因为我有很多数据需要处理。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您的好友蓝忘机已上羡 2024-12-28 08:43:05

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文