strtotime显示以前日期的当前年份

strtotime always shows current year even the date am passing is of past years. I checked with yyyy-mm-dd format and it works properly. The only problem is with my current format which is a text (20th Dec, 2016)

$sd = "20th Dec, 2016";
echo strtotime($sd);

Output : 1545354960 (which is GMT: Thursday, December 20, 2018 2:46:00 PM)

What is wrong here? what is the solution for this?

Thanks

The strtotime() function can only convert a limited number of formats, as detailed in the Supported Date and Time Formats section in the PHP manual.

The following note from the Date Formats page is pertinent in this case as the 2018 part of your example is interpreted as a 24-hour time value.

Note:

The "Year (and just the year)" format only works if a time string has already been found -- otherwise this format is recognised as HH MM.

You could use string manipulation (e.g. use preg_replace() or str_replace() to remove the ,) to provide a date format that PHP interprets as you want. I would prefer using a regex, eg:

$sd = "20th Dec, 2016";
echo date("y", strtotime(preg_replace("/([\w ]+),([\w ]+)/", "$1$2", $sd)));

A good alternative would be to use DateTime::createFromFormat(), with which you state exactly the format that the date string has.

$sd = "20th Dec, 2016";
$dt = DateTime::createFromFormat("dS M, Y", $sd);
echo $dt->format("d-M-Y");
echo strtotime($dt->format("d-M-Y"));