我想你正在寻找这样的东西:
例:
$in = trim('March 8 - 10');
$now = new DateTimeImmutable(); // Defaults to now
$start = DateTimeImmutable::createFromFormat('F j+', $in); // Parse month and day, ignore the rest
if ($now > $start) {
$start = $start->modify("next year");
}
$end = $start->setDate(
$start->format('Y'), // $start year
$start->format('n'), // $start month
substr($in, strrpos($in, ' ') + 1) // trailing bit of $in for day
);
echo $start->format("Y-m-d"), "\n";
echo $end->format("Y-m-d");
产量
2016-03-08
2016-03-10
给出像’November 8 – 10’这样的字符串,它会输出:
2015-11-08
2015-11-10