当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET TimeZoneInfo.GetSystemTimeZones方法代码示例

本文整理汇总了VB.NET中System.TimeZoneInfo.GetSystemTimeZones方法的典型用法代码示例。如果您正苦于以下问题:VB.NET TimeZoneInfo.GetSystemTimeZones方法的具体用法?VB.NET TimeZoneInfo.GetSystemTimeZones怎么用?VB.NET TimeZoneInfo.GetSystemTimeZones使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。


在下文中一共展示了TimeZoneInfo.GetSystemTimeZones方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Example

' 导入命名空间
Imports System.Collections.ObjectModel
Imports System.Globalization
Imports System.IO

Module Example
   Public Sub Main()
      Const OUTPUTFILENAME As String = "C:\Temp\TimeZoneInfo.txt"
      
      Dim timeZones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones() 
      Dim sw As StreamWriter = New StreamWriter(OUTPUTFILENAME, False)
      
      For Each timeZone As TimeZoneInfo in timeZones
         Dim hasDST As Boolean = timeZone.SupportsDaylightSavingTime
         Dim offsetFromUtc As TimeSpan = timeZone.BaseUtcOffset
         Dim adjustRules() As System.TimeZoneInfo.AdjustmentRule
         Dim offsetString As String
         
         sw.WriteLine("ID: {0}", timeZone.Id)
         sw.WriteLine("   Display Name: {0, 40}", timeZone.DisplayName)
         sw.WriteLine("   Standard Name: {0, 39}", timeZone.StandardName)
         sw.Write("   Daylight Name: {0, 39}", timeZone.DaylightName)
         sw.Write(iif(hasDST, "   ***Has ", "   ***Does Not Have "))
         sw.WriteLine("Daylight Saving Time***")
         offsetString = String.Format("{0} hours, {1} minutes", offsetFromUtc.Hours, offsetFromUtc.Minutes)
         sw.WriteLine("   Offset from UTC: {0, 40}", offsetString)
         adjustRules = timeZone.GetAdjustmentRules()
         sw.WriteLine("   Number of adjustment rules: {0, 26}", adjustRules.Length)  
         If adjustRules.Length > 0 Then
            sw.WriteLine("   Adjustment Rules:")
            For Each rule As TimeZoneInfo.AdjustmentRule In adjustRules
               Dim transTimeStart As TimeZoneInfo.TransitionTime = rule.DaylightTransitionStart
               Dim transTimeEnd As TimeZoneInfo.TransitionTime = rule.DaylightTransitionEnd 
               
               sw.WriteLine("      From {0} to {1}", rule.DateStart, rule.DateEnd)
               sw.WriteLine("      Delta: {0}", rule.DaylightDelta)
               If Not transTimeStart.IsFixedDateRule
                  sw.WriteLine("      Begins at {0:t} on {1} of week {2} of {3}", transTimeStart.TimeOfDay, _
                                                                                transTimeStart.DayOfWeek, _
                                                                                transTimeStart.Week, _
                                                                                MonthName(transTimeStart.Month))
                  sw.WriteLine("      Ends at {0:t} on {1} of week {2} of {3}", transTimeEnd.TimeOfDay, _
                                                                                transTimeEnd.DayOfWeek, _
                                                                                transTimeEnd.Week, _
                                                                                MonthName(transTimeEnd.Month))
               Else
                  sw.WriteLine("      Begins at {0:t} on {1} {2}", transTimeStart.TimeOfDay, _
                                                                 transTimeStart.Day, _
                                                                 MonthName(transTimeStart.Month))
                  sw.WriteLine("      Ends at {0:t} on {1} {2}", transTimeEnd.TimeOfDay, _
                                                               transTimeEnd.Day, _
                                                               MonthName(transTimeEnd.Month))
               End If
            Next
         End If            
      Next
      sw.Close()
开发者ID:VB.NET开发者,项目名称:System,代码行数:57,代码来源:TimeZoneInfo.GetSystemTimeZones


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