我需要刪除返回時間值的秒數。我得到PHP:刪除返回時間值的秒數
12:00:00
我想
12:00pm
我嘗試使用date()
但它一直返回時間爲凌晨1:00的一切。
echo date('g:ia', $timestamp);
我需要刪除返回時間值的秒數。我得到PHP:刪除返回時間值的秒數
12:00:00
我想
12:00pm
我嘗試使用date()
但它一直返回時間爲凌晨1:00的一切。
echo date('g:ia', $timestamp);
strtotime()
使用 -
echo date('g:ia', strtotime($timestamp));
的date()
功能 - string date (string $format [, int $timestamp = time() ])
- ,其中$timestamp
是是整數Unix時間戳。
你試過strtotime()
?
echo date('g:ia', strtotime("12:00:00"));
$timestamp = $timestamp - ($timestamp % 60);
換句話說,使用模數函數來減去當前分鐘數的秒數。
有時,更簡單更好(並且比strtotime更有效率)。
如果您只需要刪除秒(未PM需要),您可以同時使用MySQL或PHP:
MYSQL:
SELECT SUBSTRING(SEC_TO_TIME(seconds), 1, 5);
PHP:
$cleantime=substr($time,0,5)
都將剝離關秒並保持小時和分鐘
你的問題又是什麼? – Deepak