TSQL:如何将本地时间转换为 UTC?(SQL Server 2008) [英] TSQL: How to convert local time to UTC? (SQL Server 2008)

查看:38
本文介绍了TSQL:如何将本地时间转换为 UTC?(SQL Server 2008)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在处理一个需要处理来自不同时区和夏令时设置的全球时间数据的应用程序.这个想法是在内部以 UTC 格式存储所有内容,并且只为本地化的用户界面来回转换.SQL Server 是否提供任何机制来处理给定时间、国家和时区的翻译?

We are dealing with an application that needs to handle global time data from different time zones and daylight savings time settings. The idea is to store everything in UTC format internally and only convert back and forth for the localized user interfaces. Does the SQL Server offer any mechanisms for dealing with the translations given a time, a country and a timezone?

这一定是一个普遍的问题,所以我很惊讶谷歌不会找到任何可用的东西.

This must be a common problem, so I'm surprised google wouldn't turn up anything usable.

有什么指点吗?

推荐答案

7 年过去了......
实际上,SQL Server 2016 的这项新功能完全可以满足您的需求.
它被称为 AT TIME ZONE,考虑到 DST(夏令时)的变化,它将日期转换为指定的时区.
更多信息在这里:https://msdn.microsoft.com/en-us/library/mt612795.aspx

7 years passed and...
actually there's this new SQL Server 2016 feature that does exactly what you need.
It is called AT TIME ZONE and it converts date to a specified time zone considering DST (daylight saving time) changes.
More info here: https://msdn.microsoft.com/en-us/library/mt612795.aspx

这篇关于TSQL:如何将本地时间转换为 UTC?(SQL Server 2008)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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