问题
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