此方法用於指示DateTime的實例是否在當前時區的夏時製時間範圍內。
用法: public bool IsDaylightSavingTime ();
返回值:如果Kind屬性的值為Local或Unspecified,並且此DateTime實例的值在本地時區的夏令時範圍內,則此方法返回;如果Kind為Utc,則返回false。
以下示例程序旨在說明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.");
}
}
輸出:
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.");
}
}
輸出:
Instance of DateTime is not within the daylight saving time range for the current time zone.
參考:
相關用法
- C# Uri.IsBaseOf(Uri)用法及代碼示例
- C# Random.Next()用法及代碼示例
- C# Uri.ToString()用法及代碼示例
- C# Uri.IsWellFormedOriginalString()用法及代碼示例
- C# Uri.GetHashCode()用法及代碼示例
- C# Math.Log()用法及代碼示例
- C# Uri.FromHex()用法及代碼示例
- C# Uri.IsHexDigit()用法及代碼示例
- C# Queue.Contains()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 DateTime.IsDaylightSavingTime() Method in C#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。