问题描述
我想在C#中编写(或使用它已经退出的情况)一个函数,该函数在给定对象以及该时区中的特定开始时间。返回的时间应在提供的时区中。我想要的函数具有以下签名:
I would like to write (or use if it already exits) a function in C# that returns the date/time of the next DST transition given a System.TimeZoneInfo object and a particular "as of" time in that time zone. The time returned should be in the provided time zone. The function I want has this signature:
public DateTime GetNextTransition(DateTime asOfTime, TimeZoneInfo timeZone)
{
// Implement me!
}
例如,如果我传入东部标准时间 TimeZoneInfo对象,和1/21/2011 @ 17:00作为 asOfTime,我希望此函数返回3/13/2011 @ 2:00。
For example, if I pass in the "Eastern Standard Time" TimeZoneInfo object, and 1/21/2011@17:00 as the "asOfTime", I expect this function to return 3/13/2011@2:00.
href = http://msdn.microsoft.com/zh-cn/library/system.timezoneinfo.transitiontime.aspx> System.TimeZoneInfo.TransitionTime 结构似乎具有我需要的所有信息,但理想的情况是是某种将规则转换为实际日期的内置机制。有人有任何建议吗?
The System.TimeZoneInfo.TransitionTime structure appears to have all the information I need, but ideally there would be some sort of built-in mechanism to convert the rule into an actual date. Anyone have any suggestions?
推荐答案
看看此页面上的示例,我认为它将满足您的需求。
Take a look at the example on this page, I think it'll get what you need.
这篇关于获取发生夏时制过渡的下一个日期/时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!