sal*_*the 16
如果你想要最近的一天而不是下一天,这是一种方法.
$target = "Sunday";
$date = "07.05.2010";
// Old-school DateTime::createFromFormat
list($dom, $mon, $year) = sscanf($date, "%02d.%02d.%04d");
$date = new DateTime("$year/$mon/$dom -4 days");
// Skip ahead to $target day
$date->modify("next $target");
echo $date->format("d.m.Y");
Run Code Online (Sandbox Code Playgroud)
从PHP 5.3开始,中间部分可以很简单
$date = DateTime::createFromFormat("!d.m.Y", $date)
->modify("-4 days")->modify("next $target");
Run Code Online (Sandbox Code Playgroud)
这应该做:
echo date('d.m.Y', strtotime('next Sunday', strtotime('07.05.2010')));
Run Code Online (Sandbox Code Playgroud)