处理存储中的时区? [英] Handling timezones in storage?

查看:69
本文介绍了处理存储中的时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将所有内容存储在GMT吗?

Store everything in GMT?

以嵌入的偏移量存储输入内容的所有方式吗?

Store everything the way it was entered with an embedded offset?

每次渲染时都会进行数学运算吗?

Do the math everytime you render?

显示"1分钟前"的相对时间吗?

Display relative Times "1 minutes ago"?

推荐答案

您必须存储在UTC中-否则,您在Daylight Savings之类的历史报告和行为会变得很有趣. GMT是当地时间,相对于UTC属于夏令时(不是).

You have to store in UTC - if you don't, your historic reporting and behaviour during things like Daylight Savings goes... funny. GMT is a local time, subject to Daylight Savings relative to UTC (which is not).

如果要存储本地时间,向不同时区的用户介绍可能是一个真正的混蛋.如果您的原始数据使用UTC,则很容易调整为本地-只需添加用户的偏移量就可以了!

Presentation to users in different time-zones can be a real bastard if you're storing local time. It's easy to adjust to local if your raw data is in UTC - just add your user's offset and you're done!

Joel在其中一个播客中以一种绕过的方式谈论了这一点-他对以尽可能高的分辨率存储数据(搜索保真度"),因为当数据再次出现时,您总是可以对其进行修改.这就是为什么我说将其存储为UTC的原因,因为本地时间需要针对不在该时区的任何人进行调整,所以这是很多艰苦的工作.并且您需要存储例如在存储时间时夏时制是否生效. Yu.

Joel talked about this in one of the podcasts (in a round-about way) - he said to store your data in the highest resolution possible (search for 'fidelity'), because you can always munge it when it goes out again. That's why I say store it as UTC, as local time you need to adjust for anyone who's not in that timezone, and that's a lot of hard work. And you need to store whether, for example, daylight savings was in effect when you stored the time. Yuk.

过去,我通常在数据库中存储了两个-UTC用于排序,本地时间用于显示.这样,用户和计算机都不会感到困惑.

Often in databases in the past I've stored two - UTC for sorting, local time for display. That way neither the user nor the computer get confused.

现在,显示如下:当然,您可以执行"3分钟前"操作,但前提是您必须存储UTC-否则,在不同时区输入的数据将执行诸如显示为"-4小时前"的操作,这会吓到人们.如果您要显示实际时间,那么人们会喜欢在当地时间显示它-如果要在多个时区中输入数据,则只有在存储UTC时才能轻松做到这一点.

Now, as to display: Sure, you can do the "3 minutes ago" thing, but only if you store UTC - otherwise, data entered in different timezones is going to do things like display as "-4 hours ago", which will freak people out. If you're going to display an actual time, people love to have it in their local time - and if data's being entered in multiple timezones you can only do that with ease if you're storing UTC.

这篇关于处理存储中的时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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