Search code examples
c#dst

How to check whether a given date is DST date or not?


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.


Solution

  • 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/7122