mysql时区问题

MySQL的每个连接都有独立的时区设置,初始基于全局时区。时区设置影响NOW()、CURTIME()等函数显示及TIMESTAMP列的存储与读取,TIMESTAMP值在存储和检索时会与当前时区进行转换。UTC_TIMESTAMP()、DATE、TIME、DATETIME列不受当前时区影响,它们不存储为UTC。若要进行日期时间的本地化运算,需先转换为UTC,运算后再转换回来。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

客户端连接时时区是根据当前连接session时区设置,并且只会影响函数和timestamp存取;时区设置不影响UTC_TIMESTAMP()函数和DATE、TIME、DATETIME数据列。

 

Per-connection time zones. Each client that connects has its own time zone setting, given by the session time_zone variable. Initially, the session variable takes its value from the global time_zone variable, but the client can change its own time zone with this statement:

mysql> SET time_zone = timezone;

 

The current session time zone setting affects display and storage of time values that are zone-sensitive. This includes the values displayed by functions such as NOW() orCURTIME(), and values stored in and retrieved from TIMESTAMP columns. Values for TIMESTAMP columns are converted from the current time zone to UTC for storage, and from UTC to the current time zone for retrieval.

 

The current time zone setting does not affect values displayed by functions such as UTC_TIMESTAMP() or values in DATETIME, or DATETIME columns. Nor are values in those data types stored in UTC; the time zone applies for them only when converting from TIMESTAMP values. If you want locale-specific arithmetic for DATETIME, orDATETIME values, convert them to UTC, perform the arithmetic, and then convert back.

 

 

From: https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值