0

我正在尝试格式化日期,但它不起作用?

$date = new DateTime('23/09/2012 08:12:14 AM');
echo $date->format('l, dS F Y, H:i:s A');

有什么提示吗?

4

2 回答 2

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');
于 2012-09-23T08:48:50.540 回答
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

?>

尝试参考这个网站....会有所帮助

http://php.net/manual/en/function.date.php

于 2012-09-23T08:53:33.967 回答