0

我已经反序列化数据日期时间,并将其保存在我的数据库表列中:

\/日期(1328029200000+0700)\/

但是我可以使用查询 sql 再次将其转换为日期格式吗?

4

1 回答 1

0
declare @jsondate varchar(40) = '\/Date(1328029200000+0700)\/';
select substring(@jsondate,8,10) -- seconds
      ,substring(@jsondate,18,3) -- milliseconds
      ,substring(@jsondate,21,5) -- utc offset
      ,
-- this next expression is what you need
       cast(convert(char(20),
       dateadd(ms,1*substring(@jsondate,18,3),
       dateadd(ss,1*substring(@jsondate,8,10),'19700101'))
        ,120) + stuff(substring(@jsondate,21,5),4,0,':')
            as datetimeoffset(4));

-- result 2012-01-31 17:00:00.0000 +07:00
于 2012-10-04T12:19:36.130 回答