- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 mySQL 表,其中记录了各个不同时区的日期。在 mySQL 中执行 SELECT 语句时,如何将 DateTime 值转换为查看用户 TimeZone?
SELECT ClientID,
convert_tz(MessageDate,???,???)
MeetingType,
MeetingDate,
Comments,
CompanyName
FROM clientCompNotes
WHERE ClID = 970392281 AND CompanyID=411972145
问题是接受“MessageDate”字段中记录的日期中的任何时区,如下所示
Wed May 30 2012 12:51:02 GMT-0400 (Eastern Daylight Time)
非常感谢
丹尼斯
最佳答案
您不需要这样做。 MySQL 将为您执行时区转换,前提是您将时间存储在 TIMESTAMP
类型列中,并且正确设置了 session time_zone
变量。如 the manual 中所述:
The MySQL server maintains several time zone settings:
[...]
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 globaltime_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 fromTIMESTAMP
columns. Values forTIMESTAMP
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 inDATE
,TIME
, orDATETIME
columns. Nor are values in those data types stored in UTC; the time zone applies for them only when converting fromTIMESTAMP
values. If you want locale-specific arithmetic forDATE
,TIME
, orDATETIME
values, convert them to UTC, perform the arithmetic, and then convert back.
关于mysql - 如何将日期时间从任何区域转换为mysql中的特定区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10821105/
我是一名优秀的程序员,十分优秀!