2012-09-23 86 views

回答

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'); 
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

+0

這是什麼東西的mysql有這個問題呢? –

+1

@Havelock:date_format()[過程風格]函數是DateTime :: format()[object oriented style]的別名,所以你的陳述不是真的。 –