帮助我了解现在()对于mysql当前时间及其时区 [英] help me understand now() for mysql current time and its time zones

查看:193
本文介绍了帮助我了解现在()对于mysql当前时间及其时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我插入到mysql数据库中时,我需要帮助了解当我使用函数now()(在mysql中)mysql如何确定什么时区。日期时间格式为YYYY-MM-DD 00:00:00。你如何让用户在他们的位置找到合适的时间?

I need help understand how mysql can determine what the timezone is when I use the function now() (in mysql) when I insert into mysql database. The datetime format is YYYY-MM-DD 00:00:00. How do you get the user to get the right time at their location?

这个问题是否有意义?

Does this question make sense?

谢谢你的时间!

推荐答案

now()始终指向服务器的时区。

now() is always refer to the server time from its timezone.

如果您同时具有服务器和用户时区,

它可以通过函数 convert_tz

If you have both server and user timezone,
it can be done via function convert_tz,
such as

set @user_time_zone:='+02:00';
set @server_time_zone:='+08:00';

-- server timezone always come first
-- as now() is from server time
SELECT CONVERT_TZ(now(),@server_time_zone, @user_time_zone);

这篇关于帮助我了解现在()对于mysql当前时间及其时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆