2010-11-05 61 views
3

我有時間這樣在數據庫轉換時間可讀格式

   [open_time] => 10:00:00 
       [close_time] => 23:00:00 

我想把它轉換成可讀格式如上午10:00下午11:00

我嘗試這樣做:

$open = date("g:s a",$time['open_time']); 

$close = date("g:sa",$time['close_time']); 

,我發現了以下錯誤:

A non well formed numeric value encountered

回答

10

date需要一個整數參數,傳統的Unix timestamp。通過date預期

date('g:s a', strtotime($time['open_time'])); 

strtotime試圖將字符串轉換成整數Unix時間戳:

試試這個。

2

第二個參數需要一個UNIX時間戳(紀元時間):

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

timestamp

The optional timestamp parameter is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().

<?php 
$t = time(); 
print_r($t); 
print_r(date('g:i a', $t)); 
?> 

1288935001 
10:30 pm