如何修改时区除了现有的表 [英] How to modify existing tables for timezone addition

查看:120
本文介绍了如何修改时区除了现有的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有500多个表的大型应用程序,我必须将应用程序转换为可以感知时区(当前应用程序使用新java.util.Date() GETDATE()与服务器的时区)。即,无时区支持任何责任。

I have a large application with 500+ tables, I have to convert the application to be timezone aware (currently application uses new java.util.Date(), GETDATE() with server's timezone). i.e. no timezone support whatsoever.

我已经组织了这次的任务变成了几步,以简化开发,我的第一个确定的一步就是要改变所有的旧日期 UTC基于服务器的时区。 (主要是位于一个时区,所以这是我最好的猜测)

I have organised this task into a few steps so as to ease development, my first identified step is to change all old dates to UTC based on the server's timezone. (mostly located in one timezone, so this is my best guess)

接下来,我需要修改数据库和应用程序code保存在UTC的所有日期与区名称和偏移,这是我的问题就来了......在

Next, I need to modify the database and application code to save all dates in UTC with a timezone name and offset, this is where my problem comes in...

我会如何修改数据库/表来支持这一个很好的方式?

How would i go about modifying the database/tables to support this in a good manner?

我的想法是为:


  1. 为表中的每个日期/时间列,添加两个额外的列(TZ-名和放大器;偏置)

    • 这种感觉就像糟糕的设计


  • 虽然更便携,此表将包含数百万行evetually,因为它是整个数据库的日期塞进一个表


  • 虽然不便于携带,这似乎是最好的(关系)选项

有没有人有任何其他想法或最佳做法?

Does anyone have any other ideas or best-practices?

推荐答案

在我的经验,你通常应该存储数据为UTC,在一个单独的列相关的时区。具有时区表和存储时区关键是要做好与关系数据库的合理的事情。

In my experience you should generally store the data as UTC, with the relevant timezone in a separate column. Having a table for timezones and storing the timezone key is the reasonable thing to do with a relational database.

在这种情况下,虽然,所有的数据都在本地时间了,所以在这种情况下,你可以存储在时间栏本地时间,和时区添加一列。这样,你不必有已在数据库中的日期转换。

In this case though, all your data is in a local time already, so in this case you can store the local time in the time column, and add a column for the time zone. That way you don't have to convert the dates that are already in the database.

存储偏移量是没有必要的,除非你最终注意到,从时间和区域转换,以抵消太费时。

Storing offset is not necessary, unless you end up noticing that converting from date and zone to offset is too time-consuming.

这篇关于如何修改时区除了现有的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆