从php中的字符串中获取日期的最佳方法是什么[关闭]

If I want to get the 12/1/2015 from the below string and store it in a variable

The string is 12/1/2016 5:03:36 PM: going home after work

$inputDate = "12/1/2015 5:03:36 PM";
$outputDate = date('n/j/Y',strtotime($inputDate));

For more info on PHP dates visit http://php.net/manual/en/function.date.php

$yourString = '12/1/2016 5:03:36 PM: going home after work';
$explodeStr = explode(" ", $yourString);
echo $explodeStr[0]; //prints 12/1/2016

you can use explode to achieve it.