无论如何,我可以将“澳大利亚/墨尔本”转换为“澳大利亚/墨尔本”吗? 时区到一些.net基类库对象中?
我有一些来自第三方的数据,其中包括一些字符串语言
属性数据。 检索到的一些示例数据如下所示:
“澳大利亚/墨尔本”
当我调查属性数据类型的基础时,它是一个区域信息(tz 数据库/Olson 数据库)。 这是什么? 我用谷歌搜索,这是信息......
听起来许多主要平台都使用它......但 .NET 没有。
那么,在我重新发明轮子之前(或者更重要的是,更新该 codeplex 站点的代码以将 db 列表嵌入到 dll 中),这是否已经存在于 .NET 基类库中?
I have some data from a 3rd party that includes some string Language
property data. Some sample data retrieved looks like :
"Australia/Melbourne"
When i investigated that what the property data-type was based on, it's a Zone Info (tz database / Olson database). Wtf is that? i googled and here's the info....
Sounds like it's used by many major platforms ... but not .NET.
So, before i reinvent the wheel (or, more to the point, update the code from that codeplex site to embed the db list into the dll), does this already exist in the .NET base class library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一种可移植的、几乎是表示时区的标准方式。 遗憾的是 .NET 不能正确支持它,IMO。
您使用的是.NET 3.5吗? 如果是这样,
TimeZoneInfo
类是我们获得的最佳支持,但从 Olson 名称转换为 Windows 名称可能会很棘手。 理想情况下,您希望将 Olson ID 转换为 Windows 使用的 ID...但我不知道是否有可用的转换。编辑:经过一点挖掘,有几个链接:
我不知道这些文件多久更新一次,但它们很可能是您最好的选择。
It's the portable, pretty much standard way of representing time zones. It's a shame that .NET doesn't support it properly, IMO.
Are you using .NET 3.5? If so, the
TimeZoneInfo
class is the best support we've got, but converting from the Olson name to the Windows name may be tricky. Ideally you want a conversion from Olson ID to the ID that Windows uses... I don't know that there's one available though.EDIT: After little bit of digging, a couple of links:
I don't know how often these are kept up to date, but they may well be your best bet.
Code Project 上有一个很棒的小型 .Net 库,它完全可以满足您的需求:
http: //www.codeproject.com/KB/locale/zoneinfo_dotnet_api.aspx
http://zoneinfo.codeplex.com /
我在几个与 Google API 通信的项目中使用了它,因为它们的所有时区都采用 ZoneInfo/Olsen 数据库格式。
我还写了一篇关于设置它的博客文章: http://www.diaryofaninja.com/blog/2011/05/27/how-to-use-zoneinfotz-time-zones-in-net-applications
There is a great little .Net library over on Code Project that does EXACTLY what you need:
http://www.codeproject.com/KB/locale/zoneinfo_dotnet_api.aspx
http://zoneinfo.codeplex.com/
i use this on several projects that talk to Google API's as all their time zones are in ZoneInfo/Olsen database format.
I also wrote a blog post on setting it up: http://www.diaryofaninja.com/blog/2011/05/27/how-to-use-zoneinfotz-time-zones-in-net-applications
将其转换为格林威治标准时间?
查找 +x hrs 或 -x hrs & 然后从您存储的日期/时间中减去偏移量。
例如。 在你的例子中减去 10,因为墨尔本是 +10 GMT ??
convert it to GMT ?
lookup the +x hrs or -x hrs & then subtract the offset from the date/time you have stored.
eg. in your example subtract 10, as melbourne is +10 GMT ??