无论如何在PHP中强制使用日期时间格式的字符串?

You can see all the accepted datetime formats here.

$timeString = 'Y-m-d';
$this->isDateTimeFormat($trimeString); // returns true
$this->isDateTimeFormat('Sponge Bob'); // returns false

I am not interested in solving this with regex, I already have one problem. But perhaps someone knows of a way to check if a string fits the requirements and then throws an exception if it doesn't?

Thanks :)

Run the strtotime function on the date.

If it returns anything other than 0, false, or -1, it's a good date.

If you want it in a specific format after that, just put a date format on it.
I always add the date formatting because, as Boaz said, it accepts "tomorrow" or "+2 weeks" as a date.