如何使用PHP转换为schema.org JSON-LD持续时间

问题描述 投票:0回答:1

schema.org中的持续时间JSON-LD的格式为“持续时间”:“ PT4M5S”,应为ISO-8601但在PHP中,date('c')应该返回类似2004-02-12T15:19:21 + 00:00这样的字符串,它似乎采用了其他格式

我有时间以这种格式“ 00:03:06”,我需要以schema.org JSON-LD格式获取它,不确定PHP是否有任何方法可以做到这一点

https://schema.org/duration

php schema.org json-ld
1个回答
0
投票

类似的东西可能是一种转换的方法

$time = new DateTime('00:03:06');

echo sprintf('PT%dM%dS', (int)$time->format('i'), (int)$time->format('s'));

输出:PT3M6S

© www.soinside.com 2019 - 2024. All rights reserved.