UTC시간을 로컬 시간으로 변경해주는 함수
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo]. [utctolocaltime] ( @times int )
returns datetime
as
begin
declare @ret datetime
declare @offset bigint, @localdate bigint;
set @offset = datediff(second ,getdate(), getutcdate());
set @localdate = @times - @offset;
select @ret = dateadd(second , @localdate , '1970/01/01 00:00:00' )
return @ret
end
GO
함수 호출 방법:
파라미터 타입 -> int(UTC 시간)
select dbo.utctolocaltime(1457241219) as localtime;