时区、CDO、美国东部标准时间

发布于 2024-11-10 14:06:14 字数 1480 浏览 2 评论 0原文

我需要实时时区专家的帮助!

我的目标是编写一个工具(在 .Net 中),该工具将显示 SharePoint 数据库中带有选定时区偏移的日期时间值。我发现 SharePoint 在其数据库中将日期时间值保留为 UTC。它显示它们的时区偏移量,存储为 int (0 .. ~50)。稍微调查一下,发现 int 值是 CDO 代码。除了我根据不同来源编写的手动映射之外,没有其他方法可以转换 CDO 代码。

现在,我的单元测试失败,其值如下:CDO 为 34,UTC 时间为 2011-05-26 14:55:00。从 GUI 方面来看,时区看起来像“(GMT-05:00) Indiana (East)”。在我的地图中,34 对应于“美国东部标准时间”时区 ID。

var id = "US Eastern Standard Time";
var zone = TimeZoneInfo.FindSystemTimeZoneById(id);
Console.WriteLine(zone);
Console.WriteLine(zone.StandardName);

结果是:

(GMT-05:00) Indiana (East)
US Eastern Standard Time

看起来没问题,都是“印第安纳州(东部)”。现在,我使用区域来转换值:

var dateTime = new DateTime(2011, 05, 26, 14, 55, 00);
var converted = TimeZoneInfo.ConvertTimeFromUtc(dateTime, zone);
Console.WriteLine(converted);

结果是 26.05.2011 10:55:00。但 SharePoint 将其显示为 26.05.2011 09:55:00!这就是我的单元测试失败的原因。我发现了 timezoneconverter.com 在线工具。它无法将时区设置为 CDO 或 .Net 时区 ID,因此我选择了“美国/印第安纳州/印第安纳波利斯”:

14:55:00 Thursday May 26, 2011 in UTC converts to
10:55:00 Thursday May 26, 2011 in America/Indiana/Indianapolis

我的转换器具有相同的结果。然后我选择“美国/印第安纳州/诺克斯”:

14:55:00 Thursday May 26, 2011 in UTC converts to
09:55:00 Thursday May 26, 2011 in America/Indiana/Knox

谷歌地图服务显示诺克斯位于更西边,所以看起来很正常。

当然,SharePoint 使用最后一个时区。但如何呢? CDO 代码是否有一个附加标志可以帮助找到更合适的诺克斯时区?什么是区域?它的 id 是什么?我住在美国境外,所以我几乎对这些区域感到疯狂。

谢谢你,

I need a real time zones guru help!

My goal is to write a tool (in .Net) that would show datetime values from SharePoint DB with a selected timezone offset. I've found that SharePoint keeps datetime values as UTC in its DB. It shows them with a timezone offset, that is stored as int (0 .. ~50). A little investigation showed the int value is CDO code. There is no way to convert a CDO code except manual mapping, written by me, based on different sources.

Now, I have a failed unit test with the following values: CDO is 34, time in UTC is 2011-05-26 14:55:00. From GUI side, the timezone looks like '(GMT-05:00) Indiana (East)'. In my map 34 corresponds to "US Eastern Standard Time" timezone id.

var id = "US Eastern Standard Time";
var zone = TimeZoneInfo.FindSystemTimeZoneById(id);
Console.WriteLine(zone);
Console.WriteLine(zone.StandardName);

The result is:

(GMT-05:00) Indiana (East)
US Eastern Standard Time

Looks like it's OK, both are 'Indiana (East)'. Now, I use the zone to convert the value:

var dateTime = new DateTime(2011, 05, 26, 14, 55, 00);
var converted = TimeZoneInfo.ConvertTimeFromUtc(dateTime, zone);
Console.WriteLine(converted);

And the result is 26.05.2011 10:55:00. But SharePoint shows it as 26.05.2011 09:55:00! That's why my unit test has been failed. I've discovered timezoneconverter.com online tool. It has no way to set a timezone as CDO or .Net timezone id, so I had chosen 'America/Indiana/Indianapolis':

14:55:00 Thursday May 26, 2011 in UTC converts to
10:55:00 Thursday May 26, 2011 in America/Indiana/Indianapolis

My converter has the same result. Then I chose 'America/Indiana/Knox':

14:55:00 Thursday May 26, 2011 in UTC converts to
09:55:00 Thursday May 26, 2011 in America/Indiana/Knox

Google Maps service shows Knox is located more to the west, so it looks normal.

Definitely, SharePoint uses the last timezone. But HOW? Is there an additional flag to CDO code that helps to find a more appropriate Knox timezone? What is the zone? What is its id? I'm living outside the US, so I'm almost gone crazy with the zones.

Thank you,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青芜 2024-11-17 14:06:14

使用“东部标准时间”而不是“美国东部标准时间”。

2006 年之前,印第安纳州并未参与全州夏令时,仅在某些地区参与。 “美国东部标准时间”代表较早日期/时间的不变时区。现在一切都是“东部标准时间”

亚利桑那州也有类似的情况,该州大部分地区不遵守夏令时(尽管纳瓦霍族实行夏令时)。使用“美国山地标准时间”而不是“山地标准时间”。

请注意,添加“US”+ 区域只是 Microsoft 识别这些特殊区域的方法。

Use "Eastern Standard Time" instead of "US Eastern Standard Time".

Until 2006 Indiana did not participate in daylight savings across the state, only certain areas. "US Eastern Standard Time" represents the non-changing timezone for date/times earlier. Now everything is "Eastern Standard Time"

There is a similar situation in Arizona where most of the state does not observe daylight savings time (though the Navajo nation does). There "US Mountain Standard Time" is used instead of "Mountain Standard Time".

Note that adding "US " + zone is just the Microsoft way to identify these exceptional areas.

岁月蹉跎了容颜 2024-11-17 14:06:14

如果您遇到与我类似的问题(似乎工作不正确的时区),答案是:尝试另一个时区。例如,我发现“SA Pacific Standard Time”就是我所需要的。

If you face a problem that looks like mine (a timezone that seems working incorrectly), the answer is: TRY ANOTHER TIMEZONE. For instance, I've found that "SA Pacific Standard Time" is what I need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文