本文介绍了grails / mysql时区更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完成更改应用程序时区的最佳方式是什么?我看到的方式如下:

Whats the best way to accomplish changing the timezone of an app? The way I see it the following must occur:


  1. 服务器TZ由sys admin更改

  2. 必须重新启动mysql。

  3. 数据库中的每个时间列都必须使用convert_tz或等效项更新所有值。所以要写一个mysql脚本或一个grails脚本来加载每个类的每一行,更新所有的时间字段。

显然在发生这种情况时,服务器应该被关闭,并且备份必须到位,导致错误。

Obviously the server should be taken down while this is happening, and backups must be in place incase of an error.

有没有更好/更简单的方法呢?

Is there a better/easier way to do this?

推荐答案

Java在使用日期时不使用时区;它将所有内容存储为UTC,并且仅在显示日期时使用时区。有关java日期/时间的讨论,请参阅以下链接。

如果您使用MySQL时区中的日期,时间或日期时间列类型无关紧要,如果您使用TIMESTAMP列类型时区可能重要,因为TIMESTAMP作为UTC存储但是在检索和存储值时都进行了转换。有关MySQL时区行为的讨论,请参阅

如果您担心在不同时区的多个服务器上同步对象的事情变得更复杂,请参阅以下内容进行讨论。
http://www.pubbs.net/201006/grails/2500-grails- user-how-to-get-gorm-to-store-dates-as-timestamp-in-utc-by-default-without-a-custom-hibernate-mapping-or-joda-time-plu.html

Java does not use time zones when using Dates; it stores everything as UTC and only uses time zones when displaying dates. see the following link for a discussion of java date/time.http://www.odi.ch/prog/design/datetime.phpIf your using the Date, Time, or DateTime column types in MySQL time zone does not matter, if you’re using the TIMESTAMP column type time zones may matter since the TIMESTAMP is stored as a UTC but has conversion done when both retrieving and storing the values. For a discussion of MySQL time zone behavior seehttp://dev.mysql.com/doc/refman/5.1/en/time-zone-support.htmlIf you’re worried about synchronizing objects across multiple servers in different time zones things get more complicated, see the following thread for a discussion of this.http://www.pubbs.net/201006/grails/2500-grails-user-how-to-get-gorm-to-store-dates-as-timestamp-in-utc-by-default-without-a-custom-hibernate-mapping-or-joda-time-plu.html

这篇关于grails / mysql时区更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 23:20