質問

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