gpt4 book ai didi

php - 如何使用 php mysqli 设置时间?

转载 作者:行者123 更新时间:2023-11-30 23:05:50 25 4
gpt4 key购买 nike

在我的表格中准确设置时间时,这是新手问题但是当我从数据库中检索数据时,时间的形成不正确..

    <?php

include ('includes/config.php');



$mysqli = new mysqli(DB_SERVER,DB_UNAME,DB_PASSWD,DB_NAME);

if(!$mysqli){

throw new Exception($mysqli->connect_error, $mysqli->connect_errno);

}



if(isset($_POST['addbtn'])){

$time= date("h:iA");
$tqry = $mysqli->prepare("INSERT INTO table_time(table_time.time) VALUES (?) ");

if(!$tqry){

throw new Exception($mysqli->error);
}
$tqry->bind_param('s', $time);
$tqry->execute();


}

结果与我的系统时钟相同,但提前了 +1 小时为什么?提前致谢..

最佳答案

在你的 php 脚本的顶部设置你的默认时区,看看它可能会解决你的问题

例如,

date_default_timezone_set('America/Los_Angeles');

引用:http://in3.php.net/date_default_timezone_set

关于php - 如何使用 php mysqli 设置时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21950173/

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