如何检查给定日期是否为夏令时? [英] How to check whether a given date is DST date or not?

查看:500
本文介绍了如何检查给定日期是否为夏令时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期作为字符串。没有时间信息。
例如 20131031,即2013年10月31日。

I have a date as string. There is no time info. For eg. "20131031" ie) 31 oktober 2013.

我要验证是否是DST发生的日期?
w.r.t.

I want to verify whether it is the date on which DST happens or not ? w.r.t. WesternEurope.

ie)c#是否有API,例如是否为夏令时日期?
我只想将布尔值作为十月的最后一个星期日和三月的最后一个星期日的收益。
是调整时钟的日期。

ie) Does c# have an API, to say it is a DST date or not ? I want simply a boolean as return, for the last sunday of October and last sunday of March. which are the dates on which clocks are adjusted.

推荐答案

是的,有一个API:TimeZone.GetDaylightChanges

Yes, there is an API: TimeZone.GetDaylightChanges

http://msdn.microsoft.com/zh-cn/library/system.timezone.getdaylightchanges.aspx

您提供了一年,它将返回一个DaylightTime对象,其中包含夏令时的开始和结束日期。然后,您可以将您的日期与这两个日期进行比较,以确定是否为DLS日期。

You provide a year and it will return a DaylightTime object, which contains the start and end dates for daylight saving. You can then compare your date against those two to determine if its a DLS date or not.

尽管此答案已被接受,请查看下面的Matt Johnson答案以了解详细信息这不是最佳答案,也不应该使用 TimeZoneInfo 类。 https://stackoverflow.com/a/19523173/7122

Whilst this answer has been accepted, please see Matt Johnson's answer below for details why it's not the best answer and why the TimeZoneInfo class should be used instead. https://stackoverflow.com/a/19523173/7122

这篇关于如何检查给定日期是否为夏令时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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