本文整理匯總了C#中System.TimeZoneInfo.IsDaylightSavingTime方法的典型用法代碼示例。如果您正苦於以下問題:C# TimeZoneInfo.IsDaylightSavingTime方法的具體用法?C# TimeZoneInfo.IsDaylightSavingTime怎麽用?C# TimeZoneInfo.IsDaylightSavingTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了TimeZoneInfo.IsDaylightSavingTime方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DisplayDateWithTimeZoneName
private void DisplayDateWithTimeZoneName(DateTime date1, TimeZoneInfo timeZone)
{
Console.WriteLine("The time is {0:t} on {0:d} {1}",
date1,
timeZone.IsDaylightSavingTime(date1) ?
timeZone.DaylightName : timeZone.StandardName);
}
輸出:
The time is 1:00 AM on 4/2/2006 Pacific Standard Time
示例2: DateTime
DateTime unclearDate = new DateTime(2007, 11, 4, 1, 30, 0);
// Test if time is ambiguous.
Console.WriteLine("In the {0}, {1} is {2}ambiguous.",
TimeZoneInfo.Local.DisplayName,
unclearDate,
TimeZoneInfo.Local.IsAmbiguousTime(unclearDate) ? "" : "not ");
// Test if time is DST.
Console.WriteLine("In the {0}, {1} is {2}daylight saving time.",
TimeZoneInfo.Local.DisplayName,
unclearDate,
TimeZoneInfo.Local.IsDaylightSavingTime(unclearDate) ? "" : "not ");
Console.WriteLine();
// Report time as DST if it is either ambiguous or DST.
if (TimeZoneInfo.Local.IsAmbiguousTime(unclearDate) ||
TimeZoneInfo.Local.IsDaylightSavingTime(unclearDate))
Console.WriteLine("{0} may be daylight saving time in {1}.",
unclearDate, TimeZoneInfo.Local.DisplayName);
輸出:
In the (GMT-08:00) Pacific Time (US & Canada), 11/4/2007 1:30:00 AM is ambiguous. In the (GMT-08:00) Pacific Time (US & Canada), 11/4/2007 1:30:00 AM is not daylight saving time. 11/4/2007 1:30:00 AM may be daylight saving time in (GMT-08:00) Pacific Time (US & Canada).