如何UTC时间转换时间在C#中任何其它时区 [英] How to convert UTC time to Time in any other time zone in C#

查看:732
本文介绍了如何UTC时间转换时间在C#中任何其它时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#.NET的 - .NET FX 2.0这亘古不变的支持不同的时区之间进行转换。我已经写了基于UTC调度,但它给在伦敦的DTS时间1小时误差。我需要一些解决方案,这样我可以在任何相对与正确的DST调整UTC时区上山寨正确的时间。

I am working in C#.net - .Net fx is 2.0 which doesnot support converting between different time zones. I have wrote a scheduler based on UTC but it is giving errors of 1 hour in the DTS periods for London. I need some solution so that I can gat the correct time in any timezone relative to UTC with correct DST adjustments.

推荐答案

正在改变到.NET 3.5绝对出了问题?它将使你的生活非常非常容易。否则,你坚持平原的时区和DaylightSavings类,以及具有获取,使用P已知的时区/ Invoke的。

Is changing to .NET 3.5 absolutely out of the question? It would make your life much, much easier. Otherwise, you're stuck with the plain TimeZone and DaylightSavings classes, as well as having to fetch the known timezones using P/Invoke.

威廉·斯泰西拥有的博客文章有一些代码来做到这一点 - 但我还没有尝试过,所以不能担保其准确性。 (根据我的经验,他通常是相当不错的,虽然:)没有疑问的代码,如果周围的人不帮你类似位。

William Stacey has a blog post with some code to do this - but I haven't tried it, so can't vouch for its accuracy. (In my experience he's usually pretty good though :) There are no doubt similar bits of code around if that one doesn't help you.

我相信API他使用不具有访问历史数据,顺便说一句。换句话说,它会假设DST的总是的踢在十月的第一个星期日(或任何规则),而不是明知规则已随时间变化。在的TimeZoneInfo .NET 3.5支持,其中OS确实的历史数据。

I believe that the API he's using doesn't have access to historical data, btw. In other words, it will assume that DST always kicks in on the first Sunday of October (or whatever the rule is) rather than knowing that the rule has changed over time. TimeZoneInfo in .NET 3.5 supports historical data where the OS does.

这篇关于如何UTC时间转换时间在C#中任何其它时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆