简体   繁体   English

如何在 SQL Server 中将 EST 时区转换为 PST、IST、HST

[英]How to convert EST time zone to PST, IST, HST in SQL Server

As the daylight time zone changes so how would I get the correct time zone offset to get the time zone converted.随着日光时区的变化,我将如何获得正确的时区偏移量以转换时区。

Ex time difference between EST and IST is 9:30hrs but in daylight time zone(DST) it becomes 10:30 hrs. EST 和 IST 之间的 Ex 时差是 9:30 小时,但在日光时区 (DST) 中,它变为 10:30 小时。

So how would I get the correct updated timezone offset那么我将如何获得正确的更新时区偏移量

There are a number of different ways to achieve this, and you can use the AT TIME ZONE function to convert datetime values.有许多不同的方法可以实现这一点,您可以使用 AT TIME ZONE 函数来转换日期时间值。 The below example uses a CTE (CTEDateTimes) as the input for a list of UTC datetime (UTDDateTime) values for the datetimes between midnight and 04:00 22-03-13.下面的示例使用 CTE (CTEDateTimes) 作为 UTC 日期时间 (UTDDateTime) 值列表的输入,用于午夜和 22-03-13 04:00 之间的日期时间。

The following statement will return both the UTC datetime and the converted Eastern Standard Time (US).以下语句将返回 UTC 日期时间和转换后的东部标准时间(美国)。

SELECT
UTDDateTime
,CONVERT(DATETIME2(0), UTDDateTime, 126) AT TIME ZONE 'Eastern Standard Time' EST
FROM CTEDateTimes

The output for around 02:00 hours UTC are as follows: UTC 02:00 左右的输出如下:

UTCDateTime             <---> EST
----------------------- ----- ---------------------------
2022-03-13 01:57:00.000 <---> 2022-03-13 01:57:00 -05:00 
2022-03-13 01:58:00.000 <---> 2022-03-13 01:58:00 -05:00
2022-03-13 01:59:00.000 <---> 2022-03-13 01:59:00 -05:00
2022-03-13 02:00:00.000 <---> 2022-03-13 03:00:00 -04:00
2022-03-13 02:01:00.000 <---> 2022-03-13 03:01:00 -04:00
2022-03-13 02:02:00.000 <---> 2022-03-13 03:02:00 -04:00

In this way you can convert to any time zone and then find the offset.通过这种方式,您可以转换为任何时区,然后找到偏移量。

Hope this assists.希望这会有所帮助。

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

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