[英]Why can't I convert my 24 hour time to a 12 hour am/pm time with PHP?
I'm using Codeigniter and i'm having an issue where my 24 hour time column in a MySQL table is pulled by ActiveRecord & simply refuses to convert to a proper am/pm time. 我正在使用Codeigniter,但遇到了一个问题,我的MySQL表中的24小时时间列由ActiveRecord提取,并且只是拒绝转换为正确的上午/下午时间。
In my DB table, I have a time stored as 22:00:00 (10:00 PM). 在我的数据库表中,我的时间存储为22:00:00(下午10:00)。 When I pull the value from the database, the raw Unix time appears to be 1349960400 (which doesn't appear to be correct in itself) and when I run it through the date & strttotime functions it comes out as 22:00 PM.
当我从数据库中提取值时,原始Unix时间似乎是1349960400(它本身似乎并不正确),并且当我通过date&strttotime函数运行它时,它显示为22:00 PM。
This is what my code looks like: 这是我的代码如下所示:
function get_events_by_day($year, $month, $day)
{
$events = array();
$query = $this->db->select('*')
->from('calendar_events')
->where('EventDate', "$year-$month-$day", 'after')
->get();
$events = $query->result();
foreach($events as $event)
{
debug($event->EventStartTime); // prints 1349960400
debug(strtotime($event->EventStartTime)); // prints 22:00
$event->EventStartTime = date("H:i A", strtotime($event->EventStartTime));
$event->EventEndTime = date("H:i A", strtotime($event->EventEndTime));
debug($event->EventEndTime); // prints 22:00 PM
}
return $events;
}
Any thoughts would be greatly appreciated. 任何想法将不胜感激。
date("h:i A", strtotime($event->EventEndTime));
Should solve it. 应该解决它。 H is
24 h
, h = 12h
. H是
24 h
,h = 12h
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.