1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > mysql 计算时区差_在MySQL中计算时区的偏移量

mysql 计算时区差_在MySQL中计算时区的偏移量

时间:2020-05-05 17:30:54

相关推荐

mysql 计算时区差_在MySQL中计算时区的偏移量

Is there a way in MySQL to calculate the offset for any timezone?

For example, to get the local time in the timezone Asia/calcutta. What I want to do is calculate the offset for this timezone and add that offset to GMT to get the local time.

解决方案

If you want to calculate the offset of a time zone such as America/Vancouver from UTC you can do it as follows:

SELECT (unix_timestamp() - unix_timestamp(convert_tz(now(), 'Etc/UTC', 'America/Vancouver'))) / 3600 as offset;

For this to work you will first need to load the time zone information into mysql as outlined here: /doc/refman/5.0/en/mysql-tzinfo-to-sql.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。