2015-02-23 21 views
0

我現在擁有的是從數據庫記錄中以23:54(24小時制)格式提取的時間範圍。 下面我的腳本將時間範圍設置爲:上午6:30 - 下午1:00,但我希望它做的是在任何「小時」時間內放下:00,因此看起來像:6:30 am - 1pm 。從沒有必要的時候開始刪除:00

我知道這聽起來可能不重要,但能夠像所有時間一樣格式化,所以在下午1點 - 下午6點之間的事情看起來更加整潔是最終目標。 :-)

<?php 
$daystarttime = date("g:ia", strtotime($record['daystarttime'])); 
echo $daystarttime; 
$dayendtime = date("g:ia", strtotime($record['dayendtime'])); 

if (!$dayendtime == null) { 
    echo " - "; 
    echo $dayendtime; 
} 
?> 

非常感謝您的幫助。 :-)

回答

1

使用str_replace。如果有時候沒有':00',什麼都不會被替換。

$daystarttime = str_replace(':00', '', date("g:ia", strtotime($record['daystarttime']))); 
$dayendtime = str_replace(':00', '', date("g:ia", strtotime($record['dayendtime']))); 
+0

太棒了!非常感謝。對此,我真的非常感激。 :-) – cloudseeker 2015-02-23 08:20:19

相關問題