我使用此代码来显示数据库中的日期和时间。我如何修改它以从时间戳中减去6个小时。
date('m-d g:Ga', strtotime($row['time_stamp']))
发布于 2011-06-18 11:06:12
UNIX时间戳是从纪元开始的秒数。简单地减去6小时内的秒数:
date('m-d g:Ga', strtotime($row['time_stamp'])-21600)
您也可以再次使用strtotime
:
date('m-d g:Ga', strtotime('-6 hours', strtotime($row['time_stamp'])))
发布于 2011-06-18 11:12:52
因为它是在MySQL中,所以您可以让MySQL为您进行计算:
SELECT DATE_FORMAT('...', DATE_SUB(time_stamp, INTERVAL 6 HOUR)) ...
这将节省MySQL将其内部表示转换为完整字符串的开销,以及将字符串转换回另一个字符串的strtotime()解析开销。虽然strtotime有时很神奇,但它的效率肯定不高。
发布于 2014-09-15 19:36:18
$vindate=date('H:i:s',strtotime($row‘’ms_ echo _time‘)+19800);回显$vindate;
https://stackoverflow.com/questions/6393583
复制相似问题