简体   繁体   English

是否可以获得日期时间字段的时区?

[英]is it possible to get the timezone of a datetime - field?

everything that I have read about timestamp and datetime in mysql suggests that it is not possible to find out the timezone of a datetime - Field in mysql.我在 mysql 中读到的有关时间戳和日期时间的所有内容都表明无法找出日期时间的时区 - mysql 中的字段。

If that is true, isn't that a big advantage of timestamp - values compared to datetime - values?如果这是真的,那不是时间戳的一大优势 - 值与日期时间相比 - 值吗?

For example if by mistake the default-time-zone is changed and there are stored some datetime-values with例如,如果错误地更改了默认时区,并且存储了一些日期时间值

now()

you will have a hard time to fix the wrong values.您将很难修复错误的值。 Whereas with timestamp you can just set the timezone you want to have and the database changes the entries automaticly because it stores them always in UTC.而使用时间戳,您可以设置您想要的时区,并且数据库会自动更改条目,因为它始终以 UTC 存储它们。

is it possible to get the timezone of a datetime - field?是否可以获得日期时间字段的时区?

No, you cannot get timezone info from the DateTime column because it doesn't have such information.不,您无法从 DateTime 列获取时区信息,因为它没有此类信息。
Perhaps, the system or server timezone is what you are looking for.也许, systemserver时区是您正在寻找的。

isn't that a big advantage of timestamp - values compared to datetime - values?与 datetime 值相比,timestamp 值不是一个很大的优势吗?

It depends on the context.这取决于上下文。 Use a suitable data type for columns.为列使用合适的数据类型。 Not always you need to change the presentation of date+time if your server moved to another location.如果您的服务器移动到另一个位置,您并不总是需要更改日期+时间的表示。 Rather, on the contrary, once stored data must remain unchanged in most cases.相反,在大多数情况下,一旦存储的数据必须保持不变。

See:看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM