我正在尝试格式化日期,但它不起作用?
$date = new DateTime('23/09/2012 08:12:14 AM');
echo $date->format('l, dS F Y, H:i:s A');
任何提示?
答案 0 :(得分:5)
使用createFromFormat
:
$date = DateTime::createFromFormat('d/m/Y h:i:s A', '23/09/2012 08:12:14 AM');
echo $date->format('l, dS F Y, H:i:s A');
答案 1 :(得分:0)
<?php
$result = mysql_query("SELECT `datetime` FROM `table`");
$row = mysql_fetch_row($result);
$date = date_create($row[0]);
echo date_format($date, 'Y-m-d H:i:s');
#output: 2012-03-24 17:45:12
echo date_format($date, 'd/m/Y H:i:s');
#output: 24/03/2012 17:45:12
echo date_format($date, 'd/m/y');
#output: 24/03/12
echo date_format($date, 'g:i A');
#output: 5:45 PM
echo date_format($date, 'G:ia');
#output: 05:45pm
echo date_format($date, 'g:ia \o\n l jS F Y');
#output: 5:45pm on Saturday 24th March 2012
?>
尝试引用此网站....将有所帮助