将H:i转换为ISO 8601持续时间标准 [英] Convert H:i to ISO 8601 duration standard
问题描述
食谱的持续时间作为字符串存储在我的数据库中,如下所示:01:50
我试图将其转换为ISO 8601持续时间标准,没有成功。
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.
这是我用来调用字段并解析它的页面:
This is what I use to call the field and parse it the page:
$totalTime = ($extraField->value);
$itempr = "itemprop=\"totalTime\" content=\"$totalTime\"";
像这样,它在Google结构化数据测试工具中显示为00:50被Google接受根据我的理解,应该如下所示:PT1H50M
Like this, it appears in the Google structured data testing tool as "00:50" which is not accepted by Google. From what I understand, it should appear like this: PT1H50M
有没有人有任何想法如何将其转换为ISO 8601格式?请记住,我不是热衷于PHP开发,所以尽可能的解释。谢谢!
Has anyone got any ideas on how to convert it to the ISO 8601 format? Please, keep in mind that I am not to keen on development with PHP so be as explanatory as possible. Thanks!
推荐答案
像你已经在评论中写过:
Like you already wrote in the comments :
echo (new DateTime('01:50'))->format('\P\TG\Hi\M');
mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_time-formatrel =nofollow> TIME_FORMAT 功能:
or you can convert it already in the database using TIME_FORMAT function :
SELECT TIME_FORMAT('01:50', 'PT%kH%iM');
这篇关于将H:i转换为ISO 8601持续时间标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!