我目前正在尝试在 PHP 中显示数据库中的"时间"条目,出于某种奇怪的原因,它显示时间 + 1 分钟。
该条目是
'09:00:00'
当我的PHP代码
$schedule = DB::table('event_sessions')->get();
foreach $schedule as $session {
echo date( 'g:m A', strtotime($session->start_time)
}
它显示为
9:01 AM
是否有一些配置可能出错?我正在使用Laravel框架和MySQL。
因为m
是date()
函数中的月份!(因此,如果您想使用分钟数,请使用i
(例如 echo date( 'g:i A', strtotime("09:34"));
-> 09:34 AM
))
您也可以这样做:
echo date( 'g:m A', strtotime("09:34"));
回报是:
09:01 AM
有关date()
功能,请参阅此处的手册:http://php.net/manual/en/function.date.php
手册中的一句话:
m 月份的数字表示形式,前导零为 01 到 12