help me understand now() for mysql current time and its time zones

拜拜、爱过 提交于 2019-12-13 00:59:48

问题


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?

Thank you for your time!


回答1:


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

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);



回答2:


Your datetime format YYYY-MM-DD 00:00:00 has no timezone information, so it's irrelevant which timezone the user is in.

NOW() uses the system's time.




回答3:


the now() function return system time determine your server's time and location! mysql can not do this for u, this is your program's job!!




回答4:


The system timezone is controlled by system_time_zone variable. you can view the current system time zone using the following in the mysql prompt

SELECT @@system_time_zone;

The system time zone can be changed using --timezone=timezone_name in the mysql server option



来源:https://stackoverflow.com/questions/7411647/help-me-understand-now-for-mysql-current-time-and-its-time-zones

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!