gpt4 book ai didi

MySQL 时区

转载 作者:行者123 更新时间:2023-11-29 14:15:13 28 4
gpt4 key购买 nike

我是数据库开发新手,目前从事 MySQL 工作。我有一列包含美国的所有时区。我希望能够获取每行中每个时区的当前时间(只有时间,没有日期)。

时区数据如下:+05:00、-03:00 等等

这就是我尝试过的方法。我有两张 table ,一个国家,一个城市。时区可在“城市”表中找到。我尝试使用函数 sys date() 但它返回完整的日期和系统上的当前时间,而不是基于时区。谁能帮我吗?非常感谢

 select TimeZone, Country, sysdate() as "Current Time"  
from city, country
where Country='USA' and city.CountryId= country.CountryId;

最佳答案

您应该能够使用 convert_tz功能:

SELECT CONVERT_TZ(NOW(),'-07:00', city.TimeZone) AS Time, city.Name
FROM city, country
WHERE country.Name='USA' and city.CountryId= country.CountryId;

假设您的服务器位于 -07:00 时区。

关于MySQL 时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12811283/

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