本文整理匯總了VB.NET中System.TimeZoneInfo.ConvertTimeToUtc方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET TimeZoneInfo.ConvertTimeToUtc方法的具體用法?VB.NET TimeZoneInfo.ConvertTimeToUtc怎麽用?VB.NET TimeZoneInfo.ConvertTimeToUtc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了TimeZoneInfo.ConvertTimeToUtc方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
Module Example
Public Sub Main()
' Get time in local time zone
Dim thisTime As Date = Date.Now
Console.WriteLine("Time in {0} zone: {1}", IIf(TimeZoneInfo.Local.IsDaylightSavingTime(thisTime),
TimeZoneInfo.Local.DaylightName, TimeZoneInfo.Local.StandardName), thisTime)
Console.WriteLine(" UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(thisTime, TimeZoneInfo.Local))
' Get Tokyo Standard Time zone
Dim tst As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time")
Dim tstTime As Date = TimeZoneInfo.ConvertTime(thisTime, TimeZoneInfo.Local, tst)
Console.WriteLine("Time in {0} zone: {1}", IIf(tst.IsDaylightSavingTime(tstTime),
tst.DaylightName, tst.StandardName), tstTime)
Console.WriteLine(" UTC Time: {0}", TimeZoneInfo.ConvertTimeToUtc(tstTime, tst))
End Sub
End Module
' The example displays output like the following when run on a system in the U.S.
' Pacific Standard Time zone:
' Time in Pacific Standard Time zone: 12/6/2013 10:57:51 AM
' UTC Time: 12/6/2013 6:57:51 PM
' Time in Tokyo Standard Time zone: 12/7/2013 3:57:51 AM
' UTC Time: 12/6/2013 6:57:51 PM
示例2: CDate
Dim datNowLocal As Date = Date.Now
Console.WriteLine("Converting {0}, Kind {1}:", datNowLocal, datNowLocal.Kind)
Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNowLocal), TimeZoneInfo.ConvertTimeToUtc(datNowLocal).Kind)
Console.WriteLine()
Dim datNowUtc As Date = Date.UtcNow
Console.WriteLine("Converting {0}, Kind {1}", datNowUtc, datNowUtc.Kind)
Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNowUtc), TimeZoneInfo.ConvertTimeToUtc(datNowUtc).Kind)
Console.WriteLine()
Dim datNow As Date = CDate("10/26/2007 1:32:00 PM")
Console.WriteLine("Converting {0}, Kind {1}", datNow, datNow.Kind)
Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNow), TimeZoneInfo.ConvertTimeToUtc(datNow).Kind)
Console.WriteLine()
Dim datAmbiguous As Date = #11/4/2007 1:30:00AM#
Console.WriteLine("Converting {0}, Kind {1}, Ambiguous {2}", datAmbiguous, datAmbiguous.Kind, TimeZoneInfo.Local.IsAmbiguousTime(datAmbiguous))
Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datAmbiguous), TimeZoneInfo.ConvertTimeToUtc(datAmbiguous).Kind)
Console.WriteLine()
Dim datInvalid As Date = #03/11/2007 2:30:00AM#
Console.WriteLine("Converting {0}, Kind {1}, Invalid {2}", datInvalid, datInvalid.Kind, TimeZoneInfo.Local.IsInvalidTime(datInvalid))
Try
Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datInvalid), TimeZoneInfo.ConvertTimeToUtc(datInvalid).Kind)
Catch e As ArgumentException
Console.WriteLine(" {0}: Cannot convert {1} to UTC.", e.GetType().Name, datInvalid)
End Try
Console.WriteLine()
Dim datNearMax As Date = #12/31/9999 10:00:00PM#
Console.WriteLine("Converting {0}, Kind {1}", datNearMax, datNearMax.Kind)
Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNearMax), TimeZoneInfo.ConvertTimeToUtc(datNearMax).Kind)
Console.WriteLine()
'
' This example produces the following output if the local time zone
' is Pacific Standard Time:
'
' Converting 8/31/2007 2:26:28 PM, Kind Local:
' ConvertTimeToUtc: 8/31/2007 9:26:28 PM, Kind Utc
'
' Converting 8/31/2007 9:26:28 PM, Kind Utc
' ConvertTimeToUtc: 8/31/2007 9:26:28 PM, Kind Utc
'
' Converting 10/26/2007 1:32:00 PM, Kind Unspecified
' ConvertTimeToUtc: 10/26/2007 8:32:00 PM, Kind Utc
'
' Converting 11/4/2007 1:30:00 AM, Kind Unspecified, Ambiguous True
' ConvertTimeToUtc: 11/4/2007 9:30:00 AM, Kind Utc
'
' Converting 3/11/2007 2:30:00 AM, Kind Unspecified, Invalid True
' ArgumentException: Cannot convert 3/11/2007 2:30:00 AM to UTC.
'
' Converting 12/31/9999 10:00:00 PM, Kind Unspecified
' ConvertTimeToUtc: 12/31/9999 11:59:59 PM, Kind Utc