TimeZoneInfo.DaylightName 屬性

定義

取得目前時區日光節約時間的顯示名稱。

public:
 property System::String ^ DaylightName { System::String ^ get(); };
public string DaylightName { get; }
member this.DaylightName : string
Public ReadOnly Property DaylightName As String

屬性值

時區日光節約時間的顯示名稱。

範例

下列範例會定義名為 DisplayDateWithTimeZoneName 的方法,這個方法會使用 IsDaylightSavingTime(DateTime) 方法來判斷是否要顯示時區的標準時間名稱或日光節約時間名稱。

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 example displays output similar to the following:
//    The time is 1:00 AM on 4/2/2006 Pacific Standard Time
let displayDateWithTimeZoneName (date1: DateTime) (timeZone: TimeZoneInfo) =
    printfn $"The time is {date1:t} on {date1:d} {if timeZone.IsDaylightSavingTime date1 then timeZone.DaylightName else timeZone.StandardName}" 
// The example displays output similar to the following:
//    The time is 1:00 AM on 4/2/2006 Pacific Standard Time
Private Sub DisplayDateWithTimeZoneName(date1 As Date, timeZone As TimeZoneInfo)
   Console.WriteLine("The time is {0:t} on {0:d} {1}", _
                     date1, _
                     IIf(timeZone.IsDaylightSavingTime(date1), _
                         timezone.DaylightName, timezone.StandardName))   
End Sub
' The example displays output similar to the following:
'    The time is 1:00 AM on 4/2/2006 Pacific Standard Time

備註

顯示名稱會根據隨 Windows 作業系統安裝的文化特性進行當地語系化。

DaylightName值不是 String.Emptynull 不一定表示時區支援日光節約時間的屬性。 若要判斷時區是否支援日光節約時間,請檢查其 SupportsDaylightSavingTime 屬性的值。

在大部分情況下, DaylightName 系統定義的時區屬性不是 String.Emptynull 。 不過, DaylightName 自訂時區的 屬性可以設定為 String.Empty 。 當 或 多載建立 TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String)TimeZoneInfo.CreateCustomTimeZone(String, TimeSpan, String, String, String, TimeZoneInfo+AdjustmentRule[], Boolean) 自訂時區且 disableDaylightSavingTime 參數為 true 時,就會發生這種情況。 因此,您的程式碼絕對不應該假設 屬性的值不是 null 或空的 DaylightName

屬性 DaylightName 相當於 DaylightName 類別的 TimeZone 屬性。

適用於