本文整理汇总了VB.NET中System.TimeZoneInfo.GetAmbiguousTimeOffsets方法的典型用法代码示例。如果您正苦于以下问题:VB.NET TimeZoneInfo.GetAmbiguousTimeOffsets方法的具体用法?VB.NET TimeZoneInfo.GetAmbiguousTimeOffsets怎么用?VB.NET TimeZoneInfo.GetAmbiguousTimeOffsets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了TimeZoneInfo.GetAmbiguousTimeOffsets方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: ShowPossibleUtcTimes
Private Sub ShowPossibleUtcTimes(ambiguousTime As Date, timeZone As TimeZoneInfo)
' Determine if time is ambiguous in target time zone
If Not timeZone.IsAmbiguousTime(ambiguousTime) Then
Console.WriteLine("{0} is not ambiguous in time zone {1}.", _
ambiguousTime, _
timeZone.DisplayName)
Else
' Display time and its time zone (local, UTC, or indicated by timeZone argument)
Dim originalTimeZoneName As String
If ambiguousTime.Kind = DateTimeKind.Utc Then
originalTimeZoneName = "UTC"
ElseIf ambiguousTime.Kind = DateTimeKind.Local Then
originalTimeZoneName = "local time"
Else
originalTimeZoneName = timeZone.DisplayName
End If
Console.WriteLine("{0} {1} maps to the following possible times:", _
ambiguousTime, originalTimeZoneName)
' Get ambiguous offsets
Dim offsets() As TimeSpan = timeZone.GetAmbiguousTimeOffsets(ambiguousTime)
' Handle times not in time zone of timeZone argument
' Local time where timeZone is not local zone
If (ambiguousTime.Kind = DateTimeKind.Local) And Not timeZone.Equals(TimeZoneInfo.Local) Then
ambiguousTime = TimeZoneInfo.ConvertTime(ambiguousTime, TimeZoneInfo.Local, timeZone)
' UTC time where timeZone is not UTC zone
ElseIf (ambiguousTime.Kind = DateTimeKind.Utc) And Not timeZone.Equals(TimeZoneInfo.Utc) Then
ambiguousTime = TimeZoneInfo.ConvertTime(ambiguousTime, TimeZoneInfo.Utc, timeZone)
End If
' Display each offset and its mapping to UTC
For Each offset As TimeSpan In offsets
If offset.Equals(timeZone.BaseUtcOffset) Then
Console.WriteLine("If {0} is {1}, {2} UTC", ambiguousTime, timeZone.StandardName, ambiguousTime - offset)
Else
Console.WriteLine("If {0} is {1}, {2} UTC", ambiguousTime, timeZone.DaylightName, ambiguousTime - offset)
End If
Next
End If
End Sub
示例2: Date
ShowPossibleUtcTimes(#11/4/2007 1:00:00#, TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))
Console.WriteLine()
ShowPossibleUtcTimes(New Date(2007, 11, 4, 01, 00, 00, DateTimeKind.Local), _
TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))
Console.WriteLine()
ShowPossibleUtcTimes(New Date(2007, 11, 4, 00, 00, 00, DateTimeKind.Local), _
TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))
Console.WriteLine()
ShowPossibleUtcTimes(New Date(2007, 11, 4, 01, 00, 00, DateTimeKind.Unspecified), _
TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))
Console.WriteLine()
ShowPossibleUtcTimes(New Date(2007, 11, 4, 07, 00, 00, DateTimeKind.Utc), _
TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"))
'
' This example produces the following output if run in the Pacific time zone:
'
' 11/4/2007 1:00:00 AM (GMT-06:00) Central Time (US & Canada) maps to the following possible times:
' If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
' If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
'
' 11/4/2007 1:00:00 AM Pacific Standard Time is not ambiguous in time zone (GMT-06:00) Central Time (US & Canada).
'
' 11/4/2007 12:00:00 AM local time maps to the following possible times:
' If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
' If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
'
' 11/4/2007 1:00:00 AM (GMT-06:00) Central Time (US & Canada) maps to the following possible times:
' If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
' If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC
'
' 11/4/2007 7:00:00 AM UTC maps to the following possible times:
' If 11/4/2007 1:00:00 AM is Central Standard Time, 11/4/2007 7:00:00 AM UTC
' If 11/4/2007 1:00:00 AM is Central Daylight Time, 11/4/2007 6:00:00 AM UTC