gpt4 book ai didi

php - Mysql中的 block 时区转换: compare the orginal time or date value(which the user gave) to database values

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

我的表中有一个日期字段类型和一个时间字段类型。该表有一些行: 时间字段的值类似于 15:00:00 和 16:00:00;我选择了时间类型,因为我知道它不会受到时区的影响。

现在我的问题是mysql客户端(用户)时区是UTC+3,所以当用户想要选择时间是18:00:00的地方时,结果涉及时间值是15:00:00的地方(意味着给定的值)用户正在转换为 UTC;18:00:00=15:00:00)。但这不是我想要的。

我想要的是,如果用户给出 18:00:00,则应将其视为 UTC 值,以便 18:00:00 仅选择时间保存在 18:00:00 而不是 15:00:00 的行。我尝试使用 select donnees.* from donnees where timefield=CONVERT_TZ(:ptime,'UTC','Africa/Nairobi'); 但它不起作用并且给出 null 值。 p>

我真的很困惑。我怎样才能正确比较呢?

最佳答案

扩展数据库组件的“on afterOpen”事件。

在 config/main.php 中,指定“db”组件,例如:

'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=db_name',
'username' => 'db_username',
'password' => 'db_password',
'charset' => 'utf8',

'on afterOpen' => function($event) {
$event->sender->createCommand("SET time_zone = '+00:00'")->execute();
}
],

关于php - Mysql中的 block 时区转换: compare the orginal time or date value(which the user gave) to database values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36943620/

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