DateInterval: Unknown or bad format

Dong3000 picture Dong3000 · Apr 6, 2016 · Viewed 7.7k times · Source

I get several dateTime informations through an API. It's format is like P29DT48M56.941999S for example. I would like to convert it with to a readable sting using DateInterval::format. My snippet looks like

$interval = new DateInterval('P29DT48M56.941999S');
echo $interval->format(' %d days, %I minutes');

Unfortunally, I get this error:

PHP Fatal error: Uncaught exception 'Exception' with message 'DateInterval::__construct(): Unknown or bad format (P29DT48M56.941999S)'

What's wrong and how can I fix it?

Answer