问题
System returns me that date 20110408.
Is it possible to covert it to 8 April 2011? I'm using PHP5. Can't figure out how to do that with DateTime class.
回答1:
date function <--
$original_date = '20110408';
date('d F Y', strtotime($original_date));
回答2:
try these
echo date("Y-m-d H:i:s")."<br />";
echo date("F j, Y")."<br />";
echo date("j F Y")."<br />";
回答3:
You can use:
date("j F Y", strtotime('20110408'));
回答4:
You could always use:
function formatDate($date) {
// 20110408 -> 8 April 2011
$months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$year = substr($date, 0, 4);
$month = $months[intval(substr($date, 4, 2))-1];
$day = (int)substr($date, -2);
return sprintf("%d %s %d", $day, $month, $year);
}
I hope that's not too easy!
来源:https://stackoverflow.com/questions/5919387/create-user-friendly-date-in-php