DateTime - IsDaylightSavingTime
Returns a value indicating whether the specified date and time is within the specified daylight saving time period.
public static void Main() { DateTime startDate = new DateTime(2018, 3, 11); DateTime endDate = new DateTime(2018, 11, 4); TimeSpan delta = startDate - endDate; DateTime date = new DateTime(2018, 8, 9); DaylightTime daylightTimes = new DaylightTime(startDate, endDate, delta); // C# Extension Method: DateTime - IsDaylightSavingTime bool flag = date.IsDaylightSavingTime(daylightTimes); if (flag) { Console.WriteLine("{0} is a day light saving time.", date); } }
View Source
using System; using System.Globalization; public static partial class Extensions { /// <summary> /// Returns a value indicating whether the specified date and time is within the specified daylight saving time /// period. /// </summary> /// <param name="time">A date and time.</param> /// <param name="daylightTimes">A daylight saving time period.</param> /// <returns>true if is in ; otherwise, false.</returns> public static Boolean IsDaylightSavingTime(this DateTime time, DaylightTime daylightTimes) { return TimeZone.IsDaylightSavingTime(time, daylightTimes); } }