Note: Starting in the spring of 2007, daylight saving time (DST) start and end dates have changed for several time zones, including all time zones in the United States. The DaylightDate property reflects the date and time of transisition to daylight time for the current year only; changing the system time to a different year than the actual one might cause the DaylightDate property to return an incorrect value. To determine whether a specific date falls within daylight saving time, use the IsDaylightSavingTime method; this method allows the caller to specify a particular year.
Note: If no information is available in the registry, this property returns the minimum value for the DateTime data type. When this is the case, the value returned from this property should be considered undefined.
The registry supports two date formats. Absolute format specifies an exact date and time when daylight time begins. In this form, the year, month, day, hour, minute, second, and milliseconds parameters are used to specify an exact date.
"Day-in-month format" is specified by setting the year member to zero, setting the dayOfWeek member to an appropriate weekday, and using a day value in the range 1 through 5 to select the occurrence of that day of the week in the month. Using this notation, the first Sunday in April can be specified, as can the last Thursday in October (5 is equal to the last).
When the information contained in the registry is in "day-in-month" format, that information is used to calculate the date of transition for the current year.
Imports Infragistics.Win Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Get an array list of the time zones on this computer Dim timeZones As ArrayList = Infragistics.Win.Utilities.GetTimeZones() If timeZones Is Nothing Then Return ' Iterate the array list and display information on each time zone. Dim i As Int32 Dim crlf As String = vbCrLf Dim tab As String = vbTab For i = 0 To timeZones.Count - 1 Dim tzi As TimeZoneInfo = timeZones(i) Dim info As String = String.Empty info += "Time Zone: " + tzi.StandardName + crlf info += tab + "Daylight Name: " + tzi.DaylightName + crlf info += tab + "Display Name: " + tzi.DisplayName + crlf info += crlf info += tab + "UTC Offset: " + tzi.UtcOffset.TotalHours.ToString() + " hours" + crlf info += tab + "Additional Daylight Saving Time UTC Offset: " + tzi.DaylightUtcOffset.TotalHours.ToString() + " hours" + crlf info += tab + "Additional Standard Time UTC Offset: " + tzi.StandardUtcOffset.TotalHours.ToString() + " hours" + crlf If tzi.DaylightDate <> DateTime.MinValue Then info += tab + "Daylight savings time begins on " + tzi.DaylightDate.ToLongDateString() + crlf End If If tzi.StandardDate <> DateTime.MinValue Then info += tab + "Standard time begins on " + tzi.StandardDate.ToLongDateString() + crlf End If info += crlf info += tab + "The current date is " + tzi.Today.ToLongDateString() + crlf info += tab + "The current time is " + tzi.Now.ToShortTimeString() + crlf info += crlf Dim isDST As Boolean = tzi.IsDaylightSavingTime(DateTime.Now) info += tab + "Daylight savings time is " If Not isDST Then info += "not " End If info += "in effect." + crlf Dim time As DateTime = New DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 9, 0, 0) info += tab + "At 9AM (actual time) in the current time zone, the local time is " + tzi.ToLocalTime(time).ToShortTimeString() + crlf Debug.WriteLine(info) Next End Sub
using Infragistics.Win; using System.Diagnostics; private void button1_Click(object sender, System.EventArgs e) { // Get an array list of the time zones on this computer ArrayList timeZones = Infragistics.Win.Utilities.GetTimeZones(); if ( timeZones == null ) return; // Iterate the array list and display information on each time zone. int i; string crlf = "\r\n"; string tab = "\t"; for ( i = 0; i < timeZones.Count; i ++ ) { TimeZoneInfo tzi = timeZones[i] as TimeZoneInfo; string info = string.Empty; info += "Time Zone: " + tzi.StandardName + crlf; info += tab + "Daylight Name: " + tzi.DaylightName + crlf; info += tab + "Display Name: " + tzi.DisplayName + crlf; info += crlf; info += tab + "UTC Offset: " + tzi.UtcOffset.TotalHours.ToString() + " hours" + crlf; info += tab + "Additional Daylight Saving Time UTC Offset: " + tzi.DaylightUtcOffset.TotalHours.ToString() + " hours" + crlf; info += tab + "Additional Standard Time UTC Offset: " + tzi.StandardUtcOffset.TotalHours.ToString() + " hours" + crlf; if ( tzi.DaylightDate != DateTime.MinValue ) info += tab + "Daylight savings time begins on " + tzi.DaylightDate.ToLongDateString() + crlf; if ( tzi.StandardDate != DateTime.MinValue ) info += tab + "Standard time begins on " + tzi.StandardDate.ToLongDateString() + crlf; info += crlf; info += tab + "The current date is " + tzi.Today.ToLongDateString() + crlf; info += tab + "The current time is " + tzi.Now.ToShortTimeString() + crlf; info += crlf; bool isDST = tzi.IsDaylightSavingTime( DateTime.Now ); info += tab + "Daylight savings time is "; if ( ! isDST ) info += "not "; info += "in effect." + crlf; DateTime time = new DateTime( DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 9, 0, 0 ); info += tab + "At 9AM (actual time) in the current time zone, the local time is " + tzi.ToLocalTime(time).ToShortTimeString() + crlf; Debug.WriteLine( info ); } }
Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2