📜  C#中的DateTime.IsDaylightSavingTime()方法

📅  最后修改于: 2021-05-29 18:12:37             🧑  作者: Mango

此方法用于指示DateTime的此实例是否在当前时区的夏时制时间范围内。

下面的程序说明了DateTime.IsDaylightSavingTime()方法的用法:

范例1:

// C# program to demonstrate the
// DateTime.IsDaylightSavingTime()
// Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // creating object of DateTime
        DateTime date = new DateTime(2010, 1,
                                1, 4, 0, 15);
  
        // getting Typecode of date
        // using IsDaylightSavingTime() method;
        bool value = date.IsDaylightSavingTime();
  
        // checking the condition
        if (value)
            Console.WriteLine("Instance of DateTime is within the"
                               + " daylight saving time range for"+
                                        " the current time zone.");
  
        else
            Console.WriteLine("Instance of DateTime is not within the"
                              + " daylight saving time range for the "+
                                                  "current time zone.");
    }
}
输出:

范例2:

// C# program to demonstrate the
// DateTime.IsDaylightSavingTime()
// Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
  
        // creating object of DateTime
        DateTime date = new DateTime(1970, 1,
                                 1, 4, 0, 15);
  
        // getting Typecode of date
        // using IsDaylightSavingTime() method;
        bool value = date.IsDaylightSavingTime();
  
        // checking the condition
        if (value)
            Console.WriteLine("Instance of DateTime is within the"
                              + " daylight saving time range for "+
                                         "the current time zone.");
  
        else
            Console.WriteLine("Instance of DateTime is not within the"
                              + " daylight saving time range for the "+
                                                 "current time zone.");
    }
}
输出:

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.datetime.isdaylightsavingtime?view=netframework-4.7.2