วิธีการ DateTime.IsDaylightSavingTime() ใน C# ใช้เพื่อระบุว่าอินสแตนซ์ของ 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.