调整日期的时区,使小时准确(不只是在末尾添加偏移量)
Adjust date's timezone so that hour is accurate (doesn't just add offset at the end)
难以表达但易于展示:
select getutcdate() AT TIME ZONE 'UTC'
^ returns 2018-11-30 01:13:30.293 +00:00
select getutcdate() AT TIME ZONE 'UTC' AT TIME ZONE 'US Eastern Standard Time'
^returns 2018-11-29 20:13:30.293 -05:00
我需要打印的不是上面调整后的本地时间格式:
2018-11-29 15:13:30.293 (hour adjusted - no offset)
谢谢!
在时区 returns DateTimeOffset 值。
您可以将其转换为另一种 DateTime 类型,或者(在大多数情况下更好)在客户端进行格式化。
试试这个:
select getutcdate() AT TIME ZONE 'UTC'
select getutcdate() AT TIME ZONE 'UTC' AT TIME ZONE 'US Eastern Standard Time'
select CONVERT(datetime2, getutcdate() AT TIME ZONE 'UTC' AT TIME ZONE 'US Eastern Standard Time', 1)
难以表达但易于展示:
select getutcdate() AT TIME ZONE 'UTC'
^ returns 2018-11-30 01:13:30.293 +00:00
select getutcdate() AT TIME ZONE 'UTC' AT TIME ZONE 'US Eastern Standard Time'
^returns 2018-11-29 20:13:30.293 -05:00
我需要打印的不是上面调整后的本地时间格式:
2018-11-29 15:13:30.293 (hour adjusted - no offset)
谢谢!
在时区 returns DateTimeOffset 值。
您可以将其转换为另一种 DateTime 类型,或者(在大多数情况下更好)在客户端进行格式化。
试试这个:
select getutcdate() AT TIME ZONE 'UTC'
select getutcdate() AT TIME ZONE 'UTC' AT TIME ZONE 'US Eastern Standard Time'
select CONVERT(datetime2, getutcdate() AT TIME ZONE 'UTC' AT TIME ZONE 'US Eastern Standard Time', 1)