将 Sharepoint 时区信息转换为 Java 时区
我希望将 Sharepoint TimeZone 信息转换为 Java TimeZone 对象,以便与使用 Sharepoint REST API 的应用程序一起使用.我知道 Sharepoint 将所有时间戳存储在 UTC 中,但是,在使用 REST API 时,某些时间戳会返回时区调整,而有些则不是.两者的格式相同,除了如您所料,UTC 值以Z"结尾,而时区调整值不以Z"结尾.因此,将它们转换为 Java DateTime 对象很容易,但是如果我想始终如一地将 UTC 值返回给我的调用者,我将不得不将非 Z"值调整为 UTC.Sharepoint 允许我获取为 Sharepoint 服务器配置的 TimeZone 信息,但我需要的是从该信息到 Java TimeZone id 的映射.Sharepoint 通过 REST 提供的内容如下所示:
I'm looking to convert Sharepoint TimeZone information into a Java TimeZone object for use with my application which is using the Sharepoint REST API. I understand that Sharepoint stores all it's timestamps in UTC but, when using the REST API, some of the timestamps are returned time zone adjusted and some are not. The format is the same for both except, as you would expect, the UTC values end with a "Z" and the time zone adjusted values do not. So, it's easy enough to convert those to Java DateTime objects but if I want to consistently return UTC values to my callers, I will have to adjust the "non-Z" values to UTC. Sharepoint allows me to get the configured TimeZone information for the Sharepoint server but what I need is a mapping from that information to the Java TimeZone ids. What Sharepoint provides through REST looks like this:
描述:(GMT-07:00) 山地时间(美国和加拿大)偏差:420日光偏差:-60标准偏差:0
Description: (GMT-07:00) Mountain Time (US and Canada) Bias: 420 Daylight Bias: -60 Standard Bias: 0
它不提供任何可能指示 DST 何时开始等的信息,但我认为只要我可以将 Sharepoint描述"映射到 Java 时区 ID,我就不需要担心这一点.所以,我希望之前有人遇到过这种需求,或者可能有其他一些建议,说明我如何从 Sharepoint 的 REST API 中获取我需要的 UTC 值.
It doesn't provide any information that might indicate, say, when DST starts etc. but I figured I wouldn't need to worry about that as long as I can map the Sharepoint "Description" to a Java TimeZone id. So, I'm hoping that someone has run into this need before or perhaps has some other suggestion as to how I might get the UTC values I need from Sharepoint's REST API.
Java 使用 IANA 时区一>.
Microsoft Windows 到 IANA 时区的映射存在于 CLDR 补充说明中数据.
Mappings exist for Microsoft Windows to IANA time zones in the CLDR supplemental data.
但是,Sharepoint 时区与常规 Windows 时区并不完全相同.它们不使用 Windows 注册表中的字符串时区键(或通过 .NET 的 TimeZoneInfo
类的 Id
属性),而是使用特定于共享点.您可以在此处找到部分列表,以及更新的(非官方)列表此处.
However, Sharepoint time zones are not quite the same as regular Windows time zones. Instead of using string time zone keys like the ones found in the Windows registry (or via the Id
property of .NET's TimeZoneInfo
class), they use integer ids that are specific to Sharepoint. You can find a partial list here, and a more updated (unofficial) list here.
Sharepoint 时区描述与 Windows 时区的 DisplayName
大致匹配,但并非完美匹配.完全有可能某些 Sharepoint 时区未定义为 Windows 时区.
The Sharepoint time zone description loosely matches the DisplayName
of the Windows time zone, but it's not a perfect match. It's entirely possible that some of the Sharepoint time zones are not defined as Windows time zones.
假设您将每个 Sharepoint SPTimeZone
数字 id 映射到 TimeZoneInfo
id,那么您可以使用 CLDR 数据从那里转换为 IANA 时区.如果您可以运行 .NET 代码,那么您可以使用 Noda Time 库轻松完成此操作,如此处所述.
Assuming you mapped each Sharepoint SPTimeZone
numeric id to a TimeZoneInfo
id, then you could use the CLDR data to convert from there to IANA time zones. And if you can run .NET code, then you can do this quite easily with the Noda Time library, as described here.
更新
我继续将这些映射到合理的等价物.这些不能保证 100% 准确,但我认为它可以满足您的需求.
I went ahead and mapped these to reasonable equivalents. These aren't guaranteed to be 100% accurate, but I think it will give you what you need.
- 完整映射的 CSV 电子表格
- SharePoint ID 到 IANA TZ 名称的 JSON - 准备好以任何语言使用
- CSV spreadsheet for the full mapping
- JSON for SharePoint ID to IANA TZ name - ready for you to use in any language
这些大多使用大致等效的 Windows 时区进行匹配,然后使用主要 CLDR 映射与 IANA 时区匹配.唯一的例外是:
These are mostly matched using the roughly equivalent Windows time zone, then to the IANA zone using the primary CLDR mapping. The only exceptions were:
SharePoint 区域 33 和 81 是独立的,但与单个SA 西部标准时间"窗口区域相匹配.它们分别映射到 IANA 区域
America/La_Paz
和America/Manaus
.
SharePoint 区域 41 和 92 是独立的,但与单个马加丹标准时间"窗口区域相匹配.它们分别映射到 IANA 区域 Asia/Magadan
和 Asia/Kamchatka
.
SharePoint zones 41 and 92 are separate, but matched to the single "Magadan Standard Time" windows zone. They map to IANA zones Asia/Magadan
and Asia/Kamchatka
respectively.