Domanda

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!

È stato utile?

Soluzione

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().

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top