gpt4 book ai didi

php - 我怎样才能只显示小时和分钟?

转载 作者:行者123 更新时间:2023-11-29 01:45:16 25 4
gpt4 key购买 nike

我在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com