我希望转换一个有DATETIMEOFFSET
场,下降到DATETIME
字段但通过注意偏移量来重新计算时间。实际上,这将值转换为UTC
.
eg.
CreatedOn: 2008-12-19 17:30:09.0000000 +11:00
将被转换为
CreatedOn: 2008-12-19 06:30:09.0000000
or
CreatedOn: 2008-12-19 06:30:09.0000000 + 00:00 -- that's a `DATETIMEOFFSET`, but `UTC`.
干杯:)
使用几乎任何样式进行转换都会导致 datetime2 值转换为 UTC。
此外,从 datetime2 到 datetimeoffset 的转换只是将偏移量设置为+00:00
,根据下面的内容,所以这是一种快速转换的方法Datetimeoffset(offset!=0)
to Datetimeoffset(+00:00)
declare @createdon datetimeoffset
set @createdon = '2008-12-19 17:30:09.1234567 +11:00'
select CONVERT(datetime2, @createdon, 1)
--Output: 2008-12-19 06:30:09.12
select convert(datetimeoffset,CONVERT(datetime2, @createdon, 1))
--Output: 2008-12-19 06:30:09.1234567 +00:00
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)