本文整理汇总了VB.NET中System.DateTimeOffset.ToString方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DateTimeOffset.ToString方法的具体用法?VB.NET DateTimeOffset.ToString怎么用?VB.NET DateTimeOffset.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: TimeSpan
Dim thisDate As DateTimeOffset
' Show output for UTC time
thisDate = DateTimeOffset.UtcNow
Console.WriteLine(thisDate.ToString()) ' Displays 3/28/2007 7:13:50 PM +00:00
' Show output for local time
thisDate = DateTimeOffset.Now
Console.WriteLine(thisDate.ToString()) ' Displays 3/28/2007 12:13:50 PM -07:00
' Show output for arbitrary time offset
thisDate = thisDate.ToOffset(new TimeSpan(-5, 0, 0))
Console.WriteLine(thisDate.ToString()) ' Displays 3/28/2007 2:13:50 PM -05:00
示例2: Example
' 导入命名空间
Imports System.Globalization
Imports System.Threading
Module Example
Public Sub Main()
Dim date1 As New DateTimeOffset(#1/1/550#, TimeSpan.Zero)
Dim dft As CultureInfo
Dim arSY As New CultureInfo("ar-SY")
arSY.DateTimeFormat.Calendar = New HijriCalendar()
' Change current culture to ar-SY.
dft = Thread.CurrentThread.CurrentCulture
Thread.CurrentThread.CurrentCulture = arSY
' Display the date using the current culture's calendar.
Try
Console.WriteLine(date1.ToString())
Catch e As ArgumentOutOfRangeException
Console.WriteLine("{0} is earlier than {1:d} or later than {2:d}", _
date1.ToString("d", CultureInfo.InvariantCulture), _
arSY.DateTimeFormat.Calendar.MinSupportedDateTime.ToString("d", CultureInfo.InvariantCulture), _
arSY.DateTimeFormat.Calendar.MaxSupportedDateTime.ToString("d", CultureInfo.InvariantCulture))
End Try
' Restore the default culture.
Thread.CurrentThread.CurrentCulture = dft
End Sub
End Module
输出:
01/01/0550 is earlier than 07/18/0622 or later than 12/31/9999
示例3: cultures
Dim cultures() As CultureInfo = {CultureInfo.InvariantCulture, _
New CultureInfo("en-us"), _
New CultureInfo("fr-fr"), _
New CultureInfo("de-DE"), _
New CultureInfo("es-ES")}
Dim thisDate As New DateTimeOffset(#5/1/2007 9:00AM#, TimeSpan.Zero)
For Each culture As CultureInfo In cultures
Dim cultureName As String
If String.IsNullOrEmpty(culture.Name) Then
cultureName = culture.NativeName
Else
cultureName = culture.Name
End If
Console.WriteLine("In {0}, {1}", _
cultureName, thisDate.ToString(culture))
Next
' The example produces the following output:
' In Invariant Language (Invariant Country), 05/01/2007 09:00:00 +00:00
' In en-US, 5/1/2007 9:00:00 AM +00:00
' In fr-FR, 01/05/2007 09:00:00 +00:00
' In de-DE, 01.05.2007 09:00:00 +00:00
' In es-ES, 01/05/2007 9:00:00 +00:00
示例4: Example
' 导入命名空间
Imports System.Globalization
Module Example
Public Sub Main()
Dim jaJP As New CultureInfo("ja-JP")
jaJP.DateTimeFormat.Calendar = New JapaneseCalendar()
Dim date1 As New DateTimeOffset(#01/01/1867#, TimeSpan.Zero)
Try
Console.WriteLine(date1.ToString(jaJP))
Catch e As ArgumentOutOfRangeException
Console.WriteLine("{0:d} is earlier than {1:d} or later than {2:d}", _
date1, _
jaJP.DateTimeFormat.Calendar.MinSupportedDateTime, _
jaJP.DateTimeFormat.Calendar.MaxSupportedDateTime)
End Try
End Sub
End Module
输出:
1/1/1867 is earlier than 9/8/1868 or later than 12/31/9999
示例5: DateTimeOffset
Dim outputDate As New DateTimeOffset(#10/31/2007 9:00PM#, _
New TimeSpan(-8, 0, 0))
Dim specifier As String
' Output date using each standard date/time format specifier
specifier = "d"
' Displays d: 10/31/2007
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
specifier = "D"
' Displays D: Wednesday, October 31, 2007
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
specifier = "t"
' Displays t: 9:00 PM
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
specifier = "T"
' Displays T: 9:00:00 PM
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
specifier = "f"
' Displays f: Wednesday, October 31, 2007 9:00 PM
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
specifier = "F"
' Displays F: Wednesday, October 31, 2007 9:00:00 PM
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
specifier = "g"
' Displays g: 10/31/2007 9:00 PM
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
specifier = "G"
' Displays G: 10/31/2007 9:00:00 PM
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
specifier = "M" ' 'm' is identical
' Displays M: October 31
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
specifier = "R" ' 'r' is identical
' Displays R: Thu, 01 Nov 2007 05:00:00 GMT
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
specifier = "s"
' Displays s: 2007-10-31T21:00:00
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
specifier = "u"
' Displays u: 2007-11-01 05:00:00Z
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
' Specifier is not supported
specifier = "U"
Try
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
Catch e As FormatException
Console.WriteLine("{0}: Not supported.", specifier)
End Try
specifier = "Y" ' 'y' is identical
' Displays Y: October, 2007
Console.WriteLine("{0}: {1}", specifier, outputDate.ToString(specifier))
示例6: Example
' 导入命名空间
Imports System.Globalization
Imports System.Threading
Module Example
Public Sub Main()
Dim date1 As New DateTimeOffset(#7/21/1550#, TimeSpan.Zero)
Dim dft As CultureInfo
Dim heIL As New CultureInfo("he-IL")
heIL.DateTimeFormat.Calendar = New HebrewCalendar()
' Change current culture to he-IL.
dft = Thread.CurrentThread.CurrentCulture
Thread.CurrentThread.CurrentCulture = heIL
' Display the date using the current culture's calendar.
Try
Console.WriteLine(date1.ToString("G"))
Catch e As ArgumentOutOfRangeException
Console.WriteLine("{0} is earlier than {1} or later than {2}", _
date1.ToString("d", CultureInfo.InvariantCulture), _
heIL.DateTimeFormat.Calendar.MinSupportedDateTime.ToString("d", CultureInfo.InvariantCulture), _
heIL.DateTimeFormat.Calendar.MaxSupportedDateTime.ToString("d", CultureInfo.InvariantCulture))
End Try
' Restore the default culture.
Thread.CurrentThread.CurrentCulture = dft
End Sub
End Module
输出:
07/21/1550 is earlier than 01/01/1583 or later than 09/29/2239
示例7: DateTimeOffset
Dim outputDate As New DateTimeOffset(#11/1/2007 9:00AM#, _
New TimeSpan(-7, 0, 0))
Dim format As String = "dddd, MMM dd yyyy HH:mm:ss zzz"
' Output date and time using custom format specification
Console.WriteLine(outputDate.ToString(format, Nothing))
Console.WriteLine(outputDate.ToString(format, CultureInfo.InvariantCulture))
Console.WriteLine(outputDate.ToString(format, _
New CultureInfo("fr-FR")))
Console.WriteLine(outputDate.ToString(format, _
New CultureInfo("es-ES")))
输出:
Thursday, Nov 01 2007 09:00:00 -07:00 Thursday, Nov 01 2007 09:00:00 -07:00 jeudi, nov. 01 2007 09:00:00 -07:00 jueves, nov 01 2007 09:00:00 -07:00
示例8: Example
' 导入命名空间
Imports System.Globalization
Module Example
Public Sub Main()
Dim arSA As New CultureInfo("ar-SA")
arSA.DateTimeFormat.Calendar = New UmAlQuraCalendar()
Dim date1 As New DateTimeOffset(#09/10/1890#, TimeSpan.Zero)
Try
Console.WriteLine(date1.ToString("d", arSA))
Catch e As ArgumentOutOfRangeException
Console.WriteLine("{0:d} is earlier than {1:d} or later than {2:d}", _
date1, _
arSA.DateTimeFormat.Calendar.MinSupportedDateTime, _
arSA.DateTimeFormat.Calendar.MaxSupportedDateTime)
End Try
End Sub
End Module
输出:
9/10/1890 is earlier than 4/30/1900 or later than 5/13/2029