当前位置: 代码迷 >> Sql Server >> 请教如何用sqlserver函数把Java中date的整数型值(1970年到现在的耗秒数)转换成类似yyyy-mm-dd的时间形式
  详细解决方案

请教如何用sqlserver函数把Java中date的整数型值(1970年到现在的耗秒数)转换成类似yyyy-mm-dd的时间形式

热度:131   发布时间:2016-04-27 19:27:58.0
请问怎么用sqlserver函数把Java中date的整数型值(1970年到现在的耗秒数)转换成类似yyyy-mm-dd的时间形式?
如题 谢谢各位大虾了

------解决方案--------------------
declare @a bigint
set @a = xxx --整数型值(1970年到现在的耗秒数)
select convert(datetime,dateadd(ms,@a,1070),120)
------解决方案--------------------
SQL code
declare @a bigint,@b int,@c intset @a = 1133768062703  --整数型值(1970年到现在的耗秒数)   set @b = @a/(24*60*60*1000)set @c = @a%(24*60*60*1000)select dateadd(dd,@b,dateadd(ms,@c,'1970-01-01'))
------解决方案--------------------
2007-10-16 11:32:38 在用sqlserver取应是1192534358000
select (1192505558687-1192534358000)/60/60/1000 ---相差小时数7.99980916666600
--取数
declare @a bigint,@b datetime,@c datetime
select @a=0,@b='1970-01-01',@c='1970-01-01 11:32:38' 
while @b<'2007-10-16 11:32:38'
begin
select @[email protected]+datediff(ms,@b,@c)
select @[email protected]
set @c=dateadd(dd,1,@c)
end
select @a
--用你的方法验证
declare @a bigint,@b int,@c int
set @a = 1192534358000 --整数型值(1970年到现在的耗秒数)
set @b = @a/(24*60*60*1000)
set @c = @a%(24*60*60*1000)
select dateadd(dd,@b,dateadd(ms,@c,'1970-01-01 0:0:0'))
-----------------------
2007-10-16 11:32:38.000

  相关解决方案