次の方法で共有


TimeZoneInfo.SupportsDaylightSavingTime Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets a value indicating whether the time zone has any daylight saving time rules.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public ReadOnly Property SupportsDaylightSavingTime As Boolean
public bool SupportsDaylightSavingTime { get; }

Property Value

Type: System.Boolean
true if the time zone supports daylight saving time; otherwise, false.

Remarks

On Windows systems, the value of the SupportsDaylightSavingTime property for the local time zone returned by the TimeZoneInfo.Local property reflects the setting of the Control Panel Date and Time application's checkbox that defines whether the system automatically adjusts for daylight saving time. If it is unchecked, or if no checkbox is displayed for a time zone, the value of this property is false.

Version Notes

XNA Framework

 When this property is used in the XNA Framework, it throws a NotSupportedException exception.

Examples

The following example determines whether the local time zone supports daylight saving time and, if it does, determines whether a particular date and time is ambiguous or invalid. If the time is not ambiguous or invalid, the example displays it and converts it to Coordinated Universal Time (UTC). The output is generated by a system in the U.S. Pacific Standard Time zone.

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim dateStrings() As String = {"1/1/2009 12:00 AM", "6/15/2008 3:00 PM", _ 
                              "3/9/2008 2:30 AM", "3/9/2008 3:00 AM", _
                              "11/2/2008 1:30 AM", "11/2/2008 2:20 AM"}

      For Each dateString As String In dateStrings
         Dim thisDate As Date
         If DateTime.TryParse(dateString, thisDate) Then
            If (TimeZoneInfo.Local.SupportsDaylightSavingTime)
               If TimeZoneInfo.Local.IsAmbiguousTime(thisDate) Then
                  outputBlock.Text += String.Format("{0} is ambiguous in the {1} zone.", _ 
                                                    thisDate, _
                                                    TimeZoneInfo.Local.StandardName) + vbCrLf
               ElseIf TimeZoneInfo.Local.IsInvalidTime(thisDate) Then
                  outputBlock.Text += String.Format("{0} is invalid in the {1} zone.", _
                                                    thisDate, _
                                                    TimeZoneInfo.Local.StandardName) + vbCrLf
               ElseIf TimeZoneInfo.Local.IsDaylightSavingTime(thisDate) Then
                  outputBlock.Text += String.Format("{0} {1} is {2} UTC.", _ 
                                                    thisDate, _
                                                    TimeZoneInfo.Local.DaylightName, _
                                                    thisDate.ToUniversalTime()) + vbCrLf           
               Else
                  outputBlock.Text += String.Format("{0} {1} is {2} UTC.", _ 
                                                    thisDate, _
                                                    TimeZoneInfo.Local.StandardName, _
                                                    thisDate.ToUniversalTime()) + vbCrLf                  
               End If
            Else
               outputBlock.Text += String.Format("{0} {1} is {2} UTC.", _ 
                                                 thisDate, TimeZoneInfo.Local.StandardName, _
                                                 thisDate.ToUniversalTime()) + vbCrLf                  
            End If
         End If
         outputBlock.Text += vbCrLf         
      Next                           
   End Sub
End Module
' The example displays the following output:
'    1/1/2009 12:00:00 AM Pacific Standard TIme is 1/1/2009 8:00:00 AM UTC.
'    
'    6/15/2008 3:00:00 PM Pacific Daylight Time is 6/15/2008 10:00:00 PM UTC.
'    
'    3/9/2008 2:30:00 AM is invalid in the Pacific Standard Time zone.
'    
'    3/9/2008 3:00:00 AM Pacific Daylight Time is 3/9/2008 10:00:00 AM UTC.
'    
'    11/2/2008 1:30:00 AM is ambiguous in the Pacific Standard Time zone.
'    
'    11/2/2008 2:20:00 AM Pacific Standard TIme is 11/2/2008 10:20:00 AM UTC.
using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      string[] dateStrings = {"1/1/2009 12:00 AM", "6/15/2008 3:00 PM", 
                              "3/9/2008 2:30 AM", "3/9/2008 3:00 AM", 
                              "11/2/2008 1:30 AM", "11/2/2008 2:20 AM"};
      foreach (string dateString in dateStrings)
      {
         DateTime date;
         if (DateTime.TryParse(dateString, out date))
         {
            if (TimeZoneInfo.Local.SupportsDaylightSavingTime)
            {
               if (TimeZoneInfo.Local.IsAmbiguousTime(date))
                  outputBlock.Text += string.Format("{0} is ambiguous in the {1} zone.\n", 
                                                    date, TimeZoneInfo.Local.StandardName);
               else if (TimeZoneInfo.Local.IsInvalidTime(date))
                  outputBlock.Text += string.Format("{0} is invalid in the {1} zone.\n", 
                                                    date, TimeZoneInfo.Local.StandardName);
               else if (TimeZoneInfo.Local.IsDaylightSavingTime(date))
                  outputBlock.Text += string.Format("{0} {1} is {2} UTC.\n", 
                                                    date, TimeZoneInfo.Local.DaylightName,
                                                    date.ToUniversalTime());                  
               else
                  outputBlock.Text += string.Format("{0} {1} is {2} UTC.\n", 
                                                    date, TimeZoneInfo.Local.StandardName,
                                                    date.ToUniversalTime());                  
            }
            else
            {
               outputBlock.Text += string.Format("{0} {1} is {2} UTC.\n", 
                                                 date, TimeZoneInfo.Local.StandardName,
                                                 date.ToUniversalTime());                  
            }
         }
         outputBlock.Text += "\n";         
      }                           
   }
}
// The example displays the following output:
//    1/1/2009 12:00:00 AM Pacific Standard TIme is 1/1/2009 8:00:00 AM UTC.
//    
//    6/15/2008 3:00:00 PM Pacific Daylight Time is 6/15/2008 10:00:00 PM UTC.
//    
//    3/9/2008 2:30:00 AM is invalid in the Pacific Standard Time zone.
//    
//    3/9/2008 3:00:00 AM Pacific Daylight Time is 3/9/2008 10:00:00 AM UTC.
//    
//    11/2/2008 1:30:00 AM is ambiguous in the Pacific Standard Time zone.
//    
//    11/2/2008 2:20:00 AM Pacific Standard TIme is 11/2/2008 10:20:00 AM UTC.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.