当前位置: 首页>>代码示例>>C#>>正文


C# TimeZoneInfo.IsDaylightSavingTime方法代码示例

本文整理汇总了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);   
}
开发者ID:.NET开发者,项目名称:System,代码行数:7,代码来源:TimeZoneInfo.IsDaylightSavingTime

输出:

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);
开发者ID:.NET开发者,项目名称:System,代码行数:17,代码来源:TimeZoneInfo.IsDaylightSavingTime

输出:

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).


注:本文中的System.TimeZoneInfo.IsDaylightSavingTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。