Ebay API ISO 8601 duration format to timestamp

时间秒杀一切 提交于 2019-12-22 09:29:12

问题


Ebay API provides me time in ISO 8601.

For example, it gives me item time left: P0DT0H1M4S Here is how this time is formatted: ebay duration

I want to convert this time to simple Y-m-d H:i:s format. So far I've tried date("Y-m-d", strtotime("P0DT0H1M4S")); but it does not work.


回答1:


That date interval string is an ISO 8601 duration specification and can be use with DateTime() and DateInterval()

$date = new DateTime();
$date->add(new DateInterval('P0DT0H1M4S'));
echo $date->format('Y-m-d H:i:s');

or as a one-liner (PHP 5.4+)

echo (new DateTime())->add(new DateInterval('P0DT0H1M4S'))->format('Y-m-d H:i:s');

Demo



来源:https://stackoverflow.com/questions/23141868/ebay-api-iso-8601-duration-format-to-timestamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!