简体   繁体   English

将H:i转换为ISO 8601持续时间标准

[英]Convert H:i to ISO 8601 duration standard

The duration time for a recipe is stored in my database as a string like this: "01:50" I am trying to convert it to the ISO 8601 duration standard with no success. 配方的持续时间作为字符串存储在我的数据库中:“01:50”我试图将其转换为ISO 8601持续时间标准,但没有成功。

This is what I use to call the field and parse it the page: 这是我用来调用字段并将其解析为页面的内容:

$totalTime = ($extraField->value);
$itempr = "itemprop=\"totalTime\" content=\"$totalTime\"";

Like this, it appears in the Google structured data testing tool as "00:50" which is not accepted by Google. 像这样,它在谷歌结构化数据测试工具中显示为“00:50”,谷歌不接受。 From what I understand, it should appear like this: PT1H50M 根据我的理解,它应该是这样的:PT1H50M

Has anyone got any ideas on how to convert it to the ISO 8601 format? 有没有人对如何将其转换为ISO 8601格式有任何想法? Please, keep in mind that I am not to keen on development with PHP so be as explanatory as possible. 请记住,我并不热衷于使用PHP进行开发,因此请尽可能解释。 Thanks! 谢谢!

Like you already wrote in the comments : 就像你在评论中写的那样:

echo (new DateTime('01:50'))->format('\P\TG\Hi\M');

or you can convert it already in the database using TIME_FORMAT function : 或者您可以使用TIME_FORMAT函数将其转换为数据库:

SELECT TIME_FORMAT('01:50', 'PT%kH%iM');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM