TimeZoneInfo.TransitionTime.Day 属性

定义

获取发生时间更改的日期。

public:
 property int Day { int get(); };
public int Day { get; }
member this.Day : int
Public ReadOnly Property Day As Integer

属性值

Int32

发生时间更改的日期。

示例

以下示例枚举在本地计算机上找到的时区,并显示所有固定日期转换的转换时间信息。 时间信息包括发生时间更改的日期。

private void GetFixedTransitionTimes()
{
   ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
   DateTimeFormatInfo dateInfo = CultureInfo.CurrentCulture.DateTimeFormat;
   foreach (TimeZoneInfo zone in timeZones)
   {
      TimeZoneInfo.AdjustmentRule[] adjustmentRules = zone.GetAdjustmentRules();
      foreach (TimeZoneInfo.AdjustmentRule adjustmentRule in adjustmentRules)
      {
         TimeZoneInfo.TransitionTime daylightStart = adjustmentRule.DaylightTransitionStart;
         if (daylightStart.IsFixedDateRule)
            Console.WriteLine("For {0}, daylight savings time begins at {1:t} on {2} {3} from {4:d} to {5:d}.", 
                              zone.StandardName, 
                              daylightStart.TimeOfDay,  
                              dateInfo.GetMonthName(daylightStart.Month), 
                              daylightStart.Day, 
                              adjustmentRule.DateStart, 
                              adjustmentRule.DateEnd);
         TimeZoneInfo.TransitionTime daylightEnd = adjustmentRule.DaylightTransitionEnd;
         if (daylightEnd.IsFixedDateRule)
            Console.WriteLine("For {0}, daylight savings time ends at {1:t} on {2} {3} from {4:d} to {5:d}.", 
                              zone.StandardName, 
                              daylightEnd.TimeOfDay,  
                              dateInfo.GetMonthName(daylightEnd.Month), 
                              daylightEnd.Day, 
                              adjustmentRule.DateStart, 
                              adjustmentRule.DateEnd);
      }
   }   
}
let getFixedTransitionTimes () =
    let timeZones = TimeZoneInfo.GetSystemTimeZones()
    let dateInfo = CultureInfo.CurrentCulture.DateTimeFormat
    for zone in timeZones do
        let adjustmentRules = zone.GetAdjustmentRules()
        for adjustmentRule in adjustmentRules do
            let daylightStart = adjustmentRule.DaylightTransitionStart
            if daylightStart.IsFixedDateRule then
                printfn $"For {zone.StandardName}, daylight savings time begins at {daylightStart.TimeOfDay:t} on {dateInfo.GetMonthName daylightStart.Month} {daylightStart.Day} from {adjustmentRule.DateStart:d} to {adjustmentRule.DateEnd:d}." 
            let daylightEnd = adjustmentRule.DaylightTransitionEnd
            if daylightEnd.IsFixedDateRule then
                printfn $"For {zone.StandardName}, daylight savings time ends at {daylightEnd.TimeOfDay:t} on {dateInfo.GetMonthName daylightEnd.Month} {daylightEnd.Day} from {adjustmentRule.DateStart:d} to {adjustmentRule.DateEnd:d}."
Private Sub GetFixedTransitionTimes()
   Dim timeZones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()
   For Each zone As TimeZoneInfo In timeZones
      Dim adjustmentRules() As TimeZoneInfo.AdjustmentRule = zone.GetAdjustmentRules()
      For Each adjustmentRule As TimeZoneInfo.AdjustmentRule in adjustmentRules
         Dim daylightStart As TimeZoneInfo.TransitionTime = adjustmentRule.DaylightTransitionStart
         If daylightStart.IsFixedDateRule Then
            Console.WriteLine("For {0}, daylight savings time begins at {1:t} on {2} {3} from {4:d} to {5:d}.", _
                              zone.StandardName, _
                              daylightStart.TimeOfDay, _ 
                              MonthName(daylightStart.Month), _
                              daylightStart.Day, _
                              adjustmentRule.DateStart, _
                              adjustmentRule.DateEnd)
         End If
         Dim daylightEnd As TimeZoneInfo.TransitionTime = adjustmentRule.DaylightTransitionEnd
         If daylightEnd.IsFixedDateRule Then
            Console.WriteLine("For {0}, daylight savings time ends at {1:t} on {2} {3} from {4:d} to {5:d}.", _
                              zone.StandardName, _
                              daylightEnd.TimeOfDay, _ 
                              MonthName(daylightEnd.Month), _
                              daylightEnd.Day, _
                              adjustmentRule.DateStart, _
                              adjustmentRule.DateEnd)
         End If   
      Next
   Next   
End Sub

注解

The Day property returns a valid value only if the IsFixedDateRule property is true.

属性值Day对应于方法参数CreateFixedDateRule的值day。 如果其值大于转换月份中的天数,则转换发生在该月的最后一天。

Day 属性指示应用固定日期 (规则的月份日期,例如 4 月 15 日) 。 与此相反,该 DayOfWeek 属性指示 (应用浮动日期规则的星期几,例如,11 月的第二个星期日) 。

适用于