本文整理匯總了VB.NET中System.TimeSpan.TimeSpan構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET TimeSpan構造函數的具體用法?VB.NET TimeSpan怎麽用?VB.NET TimeSpan使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在類System.TimeSpan
的用法示例。
在下文中一共展示了TimeSpan構造函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: TimeSpanCtorLDemo
' Example of the TimeSpan( Long ) constructor.
Module TimeSpanCtorLDemo
' Create a TimeSpan object and display its value.
Sub CreateTimeSpan( ticks As Long )
Dim elapsedTime As New TimeSpan( ticks )
' Format the constructor for display.
Dim ctor AS String = _
String.Format( "TimeSpan( {0} )", ticks )
' Pad the end of a TimeSpan string with spaces if
' it does not contain milliseconds.
Dim elapsedStr As String = elapsedTime.ToString( )
Dim pointIndex As Integer = elapsedStr.IndexOf( ":"c )
pointIndex = elapsedStr.IndexOf( "."c, pointIndex )
If pointIndex < 0 Then elapsedStr &= " "
' Display the constructor and its value.
Console.WriteLine( "{0,-33}{1,24}", ctor, elapsedStr )
End Sub
Sub Main( )
Console.WriteLine( _
"This example of the TimeSpan( Long ) constructor " & _
vbCrLf & "generates the following output." & vbCrLf )
Console.WriteLine( "{0,-33}{1,16}", "Constructor", "Value" )
Console.WriteLine( "{0,-33}{1,16}", "-----------", "-----" )
CreateTimeSpan( 1 )
CreateTimeSpan( 999999 )
CreateTimeSpan( -1000000000000 )
CreateTimeSpan( 18012202000000 )
CreateTimeSpan( 999999999999999999 )
CreateTimeSpan( 1000000000000000000 )
End Sub
End Module
' This example of the TimeSpan( Long ) constructor
輸出:
Constructor Value ----------- ----- TimeSpan( 1 ) 00:00:00.0000001 TimeSpan( 999999 ) 00:00:00.0999999 TimeSpan( -1000000000000 ) -1.03:46:40 TimeSpan( 18012202000000 ) 20.20:20:20.2000000 TimeSpan( 999999999999999999 ) 1157407.09:46:39.9999999 TimeSpan( 1000000000000000000 ) 1157407.09:46:40
示例2: TimeSpanCtorIIIDemo
' Example of the TimeSpan( Integer, Integer, Integer ) constructor.
Module TimeSpanCtorIIIDemo
' Create a TimeSpan object and display its value.
Sub CreateTimeSpan( hours As Integer, minutes As Integer, _
seconds As Integer )
Dim elapsedTime As New TimeSpan( hours, minutes, seconds )
' Format the constructor for display.
Dim ctor AS String = _
String.Format( "TimeSpan( {0}, {1}, {2} )", _
hours, minutes, seconds )
' Display the constructor and its value.
Console.WriteLine( "{0,-37}{1,16}", _
ctor, elapsedTime.ToString( ) )
End Sub
Sub Main()
Console.WriteLine( _
"This example of the " & _
"TimeSpan( Integer, Integer, Integer ) " & vbCrLf & _
"constructor generates the following output." & vbCrLf )
Console.WriteLine( "{0,-37}{1,16}", "Constructor", "Value" )
Console.WriteLine( "{0,-37}{1,16}", "-----------", "-----" )
CreateTimeSpan( 10, 20, 30 )
CreateTimeSpan( -10, 20, 30 )
CreateTimeSpan( 0, 0, 37230 )
CreateTimeSpan( 1000, 2000, 3000 )
CreateTimeSpan( 1000, -2000, -3000 )
CreateTimeSpan( 999999, 999999, 999999 )
End Sub
End Module
' This example of the TimeSpan( Integer, Integer, Integer )
輸出:
Constructor Value ----------- ----- TimeSpan( 10, 20, 30 ) 10:20:30 TimeSpan( -10, 20, 30 ) -09:39:30 TimeSpan( 0, 0, 37230 ) 10:20:30 TimeSpan( 1000, 2000, 3000 ) 43.02:10:00 TimeSpan( 1000, -2000, -3000 ) 40.05:50:00 TimeSpan( 999999, 999999, 999999 ) 42372.15:25:39
示例3: Example
Module Example
' Create a TimeSpan object and display its value.
Sub CreateTimeSpan( days As Integer, hours As Integer, _
minutes As Integer, seconds As Integer )
Dim elapsedTime As New TimeSpan( _
days, hours, minutes, seconds )
' Format the constructor for display.
Dim ctor AS String = _
String.Format( "TimeSpan( {0}, {1}, {2}, {3} )", _
days, hours, minutes, seconds )
' Display the constructor and its value.
Console.WriteLine( "{0,-44}{1,16}", _
ctor, elapsedTime.ToString( ) )
End Sub
Sub Main()
Console.WriteLine( "{0,-44}{1,16}", "Constructor", "Value" )
Console.WriteLine( "{0,-44}{1,16}", "-----------", "-----" )
CreateTimeSpan( 10, 20, 30, 40 )
CreateTimeSpan( -10, 20, 30, 40 )
CreateTimeSpan( 0, 0, 0, 937840 )
CreateTimeSpan( 1000, 2000, 3000, 4000 )
CreateTimeSpan( 1000, -2000, -3000, -4000 )
CreateTimeSpan( 999999, 999999, 999999, 999999 )
End Sub
End Module
輸出:
Constructor Value ----------- ----- TimeSpan( 10, 20, 30, 40 ) 10.20:30:40 TimeSpan( -10, 20, 30, 40 ) -9.03:29:20 TimeSpan( 0, 0, 0, 937840 ) 10.20:30:40 TimeSpan( 1000, 2000, 3000, 4000 ) 1085.11:06:40 TimeSpan( 1000, -2000, -3000, -4000 ) 914.12:53:20 TimeSpan( 999999, 999999, 999999, 999999 ) 1042371.15:25:39
示例4: TimeSpanCtorIIIIIDemo
' Example of the
' TimeSpan( Integer, Integer, Integer, Integer, Integer ) constructor.
Module TimeSpanCtorIIIIIDemo
' Create a TimeSpan object and display its value.
Sub CreateTimeSpan( days As Integer, hours As Integer, _
minutes As Integer, seconds As Integer, millisec As Integer )
Dim elapsedTime As New TimeSpan( _
days, hours, minutes, seconds, millisec )
' Format the constructor for display.
Dim ctor As String = _
String.Format( "TimeSpan( {0}, {1}, {2}, {3}, {4} )", _
days, hours, minutes, seconds, millisec )
' Display the constructor and its value.
Console.WriteLine( "{0,-48}{1,24}", _
ctor, elapsedTime.ToString( ) )
End Sub
Sub Main( )
Console.WriteLine( _
"This example of the " & vbCrLf & _
"TimeSpan( Integer, Integer, " & _
"Integer, Integer, Integer ) " & vbCrLf & _
"constructor generates the following output." & vbCrLf )
Console.WriteLine( "{0,-48}{1,16}", "Constructor", "Value" )
Console.WriteLine( "{0,-48}{1,16}", "-----------", "-----" )
CreateTimeSpan( 10, 20, 30, 40, 50 )
CreateTimeSpan( -10, 20, 30, 40, 50 )
CreateTimeSpan( 0, 0, 0, 0, 937840050 )
CreateTimeSpan( 1111, 2222, 3333, 4444, 5555 )
CreateTimeSpan( 1111, -2222, -3333, -4444, -5555 )
CreateTimeSpan( 99999, 99999, 99999, 99999, 99999 )
End Sub
End Module
' This example of the
' TimeSpan( Integer, Integer, Integer, Integer, Integer )
輸出:
Constructor Value ----------- ----- TimeSpan( 10, 20, 30, 40, 50 ) 10.20:30:40.0500000 TimeSpan( -10, 20, 30, 40, 50 ) -9.03:29:19.9500000 TimeSpan( 0, 0, 0, 0, 937840050 ) 10.20:30:40.0500000 TimeSpan( 1111, 2222, 3333, 4444, 5555 ) 1205.22:47:09.5550000 TimeSpan( 1111, -2222, -3333, -4444, -5555 ) 1016.01:12:50.4450000 TimeSpan( 99999, 99999, 99999, 99999, 99999 ) 104236.05:27:18.9990000