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

 

posted @ 2016-07-14 08:42  木子易  Views(2723)  Comments(0Edit  收藏  举报