可以通过以下代码轻松地在C#中完成:
DateTime startDate = new DateTime(1970,1,1).AddMilliseconds(1348203320000);我需要在SQL Server中执行此操作。我发现一些脚本 here ,但是这是从1900-01-01开始的。
我已经使用了 DATEADD 函数如下,但这是通过以毫秒为单位的差异给出了一个算术溢出异常:
SELECT DATEADD(MILLISECOND,1348203320000,'1970-1-1')如何正确地进行转换?
解决方案pre> DECLARE @UTC BIGINT SET @UTC = 1348203320997 SELECT DATEADD(MILLISECOND,@UTC%1000,DATEADD(SECOND,@UTC / 1000 ,'19700101'))
I want to convert UTC milliseconds to DateTime in SQL server.
This can easily be done in C# by following code:
DateTime startDate = new DateTime(1970, 1, 1).AddMilliseconds(1348203320000);I need to do this in SQL server. I found some script here, but this was taking initial ticks from 1900-01-01.
I have used the DATEADD function as below, but this was giving an arithmetic overflow exception by supping milliseconds as difference:
SELECT DATEADD(MILLISECOND,1348203320000,'1970-1-1')How can I do the conversion properly?
解决方案 DECLARE @UTC BIGINT SET @UTC = 1348203320997 SELECT DATEADD(MILLISECOND, @UTC % 1000, DATEADD(SECOND, @UTC / 1000, '19700101'))
更多推荐
在UTC服务器中将UTC毫秒转换为DATETIME
发布评论