简体   繁体   English

SQL Server 2016的“在时区”功能无法按预期工作

[英]SQL Server 2016's “at time zone” function not working as expected

I'm using SQL Server 2016 at Amazon AWS. 我在Amazon AWS上使用SQL Server 2016。 My emails are being sent with incorrect times when sent from my pupper at Amazon. 从亚马逊的小店寄出我的电子邮件的时间不正确。 When I try to recreate this bug locally the times are correct. 当我尝试在本地重新创建此错误时,时间是正确的。 Here is an example of how I use at time zone . 这是我如何at time zone使用的示例。

getDate() at time zone 'utc' at time zone u.timezone

where u.timezone is the user's timezone and u refers to an aliased table users . 其中u.timezone是用户的时区, u表示别名表users

The times being outputted are at UTC time, so I see 7:36pm instead of 2:36pm (they are formatted with MomentJS) 输出的时间是UTC时间,所以我看到的是7:36pm而不是2:36pm (它们是用MomentJS格式化的)

I don't really know where to start with this one, sorry guys and gals. 对不起,伙计们,我真的不知道从哪开始。

UPDATE UPDATE

My server is sending the correct time (with the correct timezone offset) to the email factory. 我的服务器正在将正确的时间(具有正确的时区偏移)发送到电子邮件工厂。 When the server creates the emails, times are formatted using MomentJS. 服务器创建电子邮件时,将使用MomentJS格式化时间。 The barebones moment() function will take a time with a timezone offset (-5:00) and adjust it to the local machine's local time. 准系统的moment()函数将花费一个带有时区偏移量(-5:00)的时间,并将其调整为本地计算机的本地时间。 Local time on my machine is EST, but in Amazon (where the email is being created) is not. 我计算机上的本地时间是EST,但是不是Amazon(正在创建电子邮件的地方)的本地时间。 Thus I must use moment.parseZone() . 因此,我必须使用moment.parseZone()

From the MomentJS docs : MomentJS文档中

If your date format has a fixed timezone offset, use moment.parseZone:
moment.parseZone("2013-01-01T00:00:00-13:00");
This results in a date with a fixed offset:
"2013-01-01T00:00:00-13:00"

Since I can't see this change until it is pushed onto our dev environment, I won't be able to know if this fixed it, but I think this was the problem. 由于直到将更改推送到我们的开发环境中之前,我才能看到它,所以我无法知道是否可以解决此问题,但是我认为这是问题所在。

My server was sending the correct time (with the correct timezone offset) to the email factory. 我的服务器向电子邮件工厂发送了正确的时间(具有正确的时区偏移)。 When the server created the emails, times were formatted using MomentJS. 服务器创建电子邮件时,使用MomentJS格式化时间。

The barebones moment() function takes a time with a timezone offset (-5:00) and adjusts it to the local machine's local time. 准系统的moment()函数将花费一个时区偏移量(-5:00),并将其调整为本地计算机的本地时间。

Local time on my machine is EST, but in Amazon (where the email is being created) is not. 我计算机上的本地时间是EST,但是不是Amazon(正在创建电子邮件的地方)的本地时间。 Thus I must use moment.parseZone() . 因此,我必须使用moment.parseZone()

Changing to moment.parseZone() fixed this issue. 更改为moment.parseZone()解决此问题。 Problem solved. 问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM