鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 数据库 > mssql > >

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

来源:互联网 作者:佚名 时间:2022-05-14 22:37
复制代码 代码如下: DECLARE @LocalDate DATETIME, @UTCDate DATETIME, @LocalDate2 DATETIME SET @LocalDate = GETDATE() SET @UTCDate = DATEADD(hour, DATEDIFF(hour,GETDATE(),GETUTCDATE()), @LocalDate) SET @LocalDate2 = DATEADD(hour, DATED
复制代码 代码如下:
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
网友评论
<