将历史日期从 UTC 转换为本地时间
我有一个包含如下数据的 sql 表:
| theDate (datetime) | theValue (int) |
----------------------------------------
| 2010-05-17 02:21:10 | 5 |
| 2009-03-12 04:11:35 | 23 |
| 2010-02-19 18:16:53 | 52 |
| 2008-07-07 22:54:11 | 30 |
日期以 UTC 格式存储在日期时间列中,如何将它们转换为当地时间(挪威)?请记住,由于冬季/夏季时间的原因,UTC 偏移量全年并不相同。
更新:我使用的是 Microsoft SQL Server 2005,我需要从 SQL 执行此操作,因为数据稍后将显示在报表中。
I have an sql table with data like this:
| theDate (datetime) | theValue (int) |
----------------------------------------
| 2010-05-17 02:21:10 | 5 |
| 2009-03-12 04:11:35 | 23 |
| 2010-02-19 18:16:53 | 52 |
| 2008-07-07 22:54:11 | 30 |
The dates are stored in UTC format in a datetime column, how can I convert them to local time (Norway)? Remember that the UTC-offset is not the same all year because of winter/summer-time.
UPDATE: I am using Microsoft SQL Server 2005, and I need to do this from SQL because the data will be shown to a report later on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
该语句将针对您列出的表起作用。使用该逻辑,您可以将其应用于任何日期字段。
This statement will work against the table you listed. Using the logic you can apply it to any date fields.
编写 CLR 函数,将 SqlDateTime 从 UTC 转换为 CLR 本地时间,如下所示:
Write you CLR function that will convert your SqlDateTime from UTC to your CLR local, something like this:
如果可以的话,使用 PHP...
Using PHP if you can...
从当地时间返回当地冬季时间
这是我的函数,根据 3 月最后一个星期日 2:00 和 10 月最后一个星期日 3:00 的时间变化
here is my function to return local winter time from local time
based on time change on last Sunday in March at 2:00 and last Sunday in October at 3:00