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.
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP