开发者

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

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!


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


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.


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!!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜