我在php中使用mysql。我如何只显示小时和分钟?
这是我的函数,它返回json格式的结果。这个功能的
function getTiming($placeId) {
$sql = "SELECT * from place_timing where placeId='$placeId'";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());
$records = array();
if (mysql_num_rows($result)==0)
{
echo '['.json_encode(array('placeId' => 0)).']';
//this is for null result
}
else
{
while($row = mysql_fetch_assoc($result))
{
$records[] = $row;
}
echo json_encode($records); //this concerts in json
}
}
输出是这样的: -
[{"placeId":"31","sun_open_time":"00:00:00","sun_close_time":"00:00:00","mon_open_time":"00:00:00","mon_close_time":"23:00:00","tue_open_time":"00:00:00","tue_close_time":"00:00:00"}]
但我想只显示小时:分钟。意味着我不想显示秒。
请建议我如何更改我的上述功能,以便我只能显示小时:分钟。
预先感谢您。
这属于[“我如何格式化MySQL日期时间”]的标准类别(http://stackoverflow.com/search?q=%5Bmysql%5D+%5Bphp%5D+change+time+format) ,例如[更改MySQL PHP中日期和时间字段的显示格式](http://stackoverflow.com/questions/2411970/change-display-format-of-date-and-time-field-in-mysql-php ) – deceze 2011-12-20 09:32:54