我正在使用 mysql 的 php 中工作。
这是我的函数,它以 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"}]
但我只想显示小时:分钟。意味着我不想显示秒。
请建议我如何更改上述功能,以便我只能显示小时:分钟。
提前谢谢您。
最佳答案
有很多方法可以做到这一点,“最干净的”是在 SELECT 子句中指定列并使用 DATE_FORMAT() 传递日期。像这样:DATE_FORMAT(sun_open_time, '%H:%i')
。
关于php - 我怎样才能只显示小时和分钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8573278/