How to store TimeZoneInfo objects in a database?

后端 未结 4 1194
旧巷少年郎
旧巷少年郎 2021-02-13 07:02

Somewhat misleading title, I know. Never actually wanted to store TimeZoneInfo object themselves: rather, I want to store some culture-neutral identifier, which can

4条回答
  •  醉梦人生
    2021-02-13 07:13

    Yes, Id is a non-localized identifier, so that's an appropriate thing to store.

    You should be aware of one possible problem though: identifiers can change over time. I don't know whether it's an issue in Windows time zone identifiers, but it certainly occurs in the Olson (zoneinfo) database. For example, I was recently looking at an issue caused by "Pacific/Ponape" changing to "Pacific/Pohnpei".

    I suspect that as Microsoft has tighter control over the IDs, they're more likely to remain the same - but even so, countries can change their names, split into different countries (potentially creating new time zones) etc.

    I'm not suggesting any fixes for this problem - just highlighting it as a potential issue. Storing the ID is probably the best approach available, but be aware of the potential risks...

提交回复
热议问题