gpt4 book ai didi

php - MYSQL时间转换为PHP时间

转载 作者:太空宇宙 更新时间:2023-11-03 12:21:23 26 4
gpt4 key购买 nike

我在 mysql 数据库中有一个时间类型的列,我想将它转换为 php 时间对象以便能够在某些函数中使用它,我尝试过使用 strtotime 函数但它对我不起作用,这是我的 PHP 代码:

$result=mysql_query("select time,name from users where user_id='1'");
if($result)
{
$row=mysql_fetch_array($result);
$time=$row['time'];
$formatted_time=strtotime($time);
echo date('H:i:s',$formatted_time);
}

但我总是得到的是:01:00:00我不知道 1 小时是从哪里来的!

我知道这个问题可能会被重复,但所有答案都在谈论使用 strtotime 函数,该函数并不如您所见。你能帮忙吗?

提前很多谢谢

最佳答案

使用TIME_FORMAT:

SELECT TIME_FORMAT('14:30:00', '%h:%i %p'); /* 02:30 PM */

TIME_FORMAT 是一个 mysql 函数,您可以在查询中使用它!

关于php - MYSQL时间转换为PHP时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19865653/

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