在UTC服务器中将UTC毫秒转换为DATETIME

编程入门 行业动态 更新时间:2024-10-12 01:22:27
本文介绍了在UTC服务器中将UTC毫秒转换为DATETIME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可以通过以下代码轻松地在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

本文发布于:2023-11-09 03:48:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571314.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   中将   服务器   UTC   DATETIME

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!