如何在PHP [日期]格式中转换字符串“290416”

This question already has an answer here:

I need to convert string value "290416" which is actually date but not in correct format. I need to change it in date format like 29/04/16. please help.

</div>

If you don't need it as a date but only in date format. Meaning you are not performing any date-functions on it but just displaying it as a date you could use

$str = '290416';
$arr = str_split($str, 2);
$date_string = $implode('/', $arr);

The most robust way will be to use createFromFormat, passing in your format and the string, and they you have a DateTime object and can do many things with it.

define('MY_DATE_INPUT_FORMAT', 'mdy');
define('MY_DATE_OUTPUT_FORMAT', 'm/d/y');
$inputDateString = '042916';
$dateObj = DateTime::createFromFormat(MY_DATE_INPUT_FORMAT, $inputDateString);
$outputString = $dateObj->format(MY_DATE_OUTPUT_FORMAT);

This can also be done procedurally:

$date = date_create_from_format(MY_DATE_INPUT_FORMAT, $inputDateString);
echo date_format($date, MY_DATE_OUTPUT_FORMAT);