Вопрос

I've been trying to create a function that converts something like 3d4h into the current unixtime+the number of seconds within that string. I unfortunately have not been successful, and now I'm turning to you all. Thanks for any help!

Это было полезно?

Решение

DateTime() and DateInterval() already do this for you:

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

This example adds an interval to "now". You can, of course, make the interval relative to any date and time.

See the interval spec for what valid values are for DateInterval().

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top