我在加拿大服务器上托管了我的网站。我的客户在不同的国家。当他们添加设备我已经存储了时区ID。例如。
'Pacific Standard Time'
'Mountain Standard Time (Mexico)'
'India Standard Time'
现在在sql server中如何从时区ID获取国家时间,该时区存储在我的数据库中,如上所述。?
答案 0 :(得分:1)
sys.time_zone_info
有UTC偏移量。这将为您提供完整的清单
SELECT * FROM sys.time_zone_info
从这里,您可以简单地加入存储在表格中的值。
MSDN页面:https://msdn.microsoft.com/en-us/library/mt612790.aspx
答案 1 :(得分:1)
从时区读取SQL Server可以是实现SQL Server安装位置的当前时区的一种方法。
DECLARE @TimeZone VARCHAR(50)
EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
'SYSTEM\CurrentControlSet\Control\TimeZoneInformation',
'TimeZoneKeyName',@TimeZone OUT
SELECT @TimeZone
答案 2 :(得分:0)
如果您使用的是SQL SERVER 2008或更高版本,可以试试这个......
SELECT [DateTimeUtil].[UDF_ConvertLocalToLocalByTimezoneIdentifier] (
'GMT Standard Time', -- the original timezone in which your datetime is stored
'Middle East Standard Time', -- the target timezone for your user
'2014-03-30 01:55:00' -- the original datetime you want to convert
)
如需更多说明,请浏览以上链接......