C# 中的 DateTime.IsDaylightSavingTime() 方法


C# 中的 DateTime.IsDaylightSavingTime() 方法用于指示 DateTime 的该实例是否位于当前时区的夏令时范围内。

语法

以下是语法 −

public bool IsDaylightSavingTime ();

示例

现在让我们看一个示例来实现 DateTime.IsDaylightSavingTime() 方法 −

using System;
public class Demo {
   public static void Main() {
      DateTime d = new DateTime(2019, 10, 11, 7, 10, 40);
      bool res = d.IsDaylightSavingTime();
      if (res)
         Console.WriteLine("TRUE: This instance of DateTime is within the daylight saving time range for the current time zone.");
      else
         Console.WriteLine("FALSE: This instance of DateTime is within the daylight saving time range for the current time zone.");
   }
}

输出

这将产生以下输出 −

FALSE: This instance of DateTime is within the daylight saving time range for the current time zone.

示例

现在让我们看另一个示例来实现 DateTime.IsDaylightSavingTime() 方法 −

using System;
public class Demo {
   public static void Main() {
      DateTime d = DateTime.Now;
      bool res = d.IsDaylightSavingTime();
      if (res)
         Console.WriteLine("TRUE: This instance of DateTime is within the daylight saving time range for the current time zone.");
      else
         Console.WriteLine("FALSE: This instance of DateTime is within the daylight saving time range for the current time zone.");
   }
}

输出

这将产生以下输出 −

FALSE: This instance of DateTime is within the daylight saving time range for the current time zone.

更新于: 08-Nov-2019

316 浏览量

开启你的 职业生涯

完成课程获取证书

立即开始
广告