Heim  >  Artikel  >  Datenbank  >  SQL Server本地时间和UTC时间的相互转换实现代码

SQL Server本地时间和UTC时间的相互转换实现代码

WBOY
WBOYOriginal
2016-06-07 18:02:051378Durchsuche

SQL Server 本地时间和UTC时间的相互转换的代码,需要的朋友可以参考下。

代码如下:
DECLARE @LocalDate DATETIME,
@UTCDate DATETIME,
@LocalDate2 DATETIME

SET @LocalDate = GETDATE()
SET @UTCDate = DATEADD(hour, DATEDIFF(hour,GETDATE(),GETUTCDATE()), @LocalDate)
SET @LocalDate2 = DATEADD(hour, DATEDIFF(hour,GETUTCDATE(),GETDATE()), @UTCDate)

SELECT '1. Now' [Now], @LocalDate [DateTime]
UNION
SELECT '2. UTC', @UTCDate
UNION
SELECT '3. Now again', @LocalDate2
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn