I have a date as string. There is no time info. For eg. "20131031" ie) 31 oktober 2013.
I want to verify whether it is the date on which DST happens or not ? w.r.t. WesternEurope.
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.
Yes, there is an API: TimeZone.GetDaylightChanges
http://msdn.microsoft.com/en-us/library/system.timezone.getdaylightchanges.aspx
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.
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/7122Per MSDN Documentation
You should consider
TimeZone
deprecated.Instead, you can check DST for the local time zone like this:
For a specific time zone, do this instead:
If you want to know when the daylight periods start and stop, you'll have to work through the transition rules from
tzi.GetAdjustmentRules()
. That can get a bit complex though. You would probably be better off using Noda Time for that.You can use the
TimeZone.IsDaylightSavingTime
method, it takes aDateTime
:So for example:
See MSDN for more information.