TimeSpan Constructor (Int32, Int32, Int32)

May 11, 2014

Initializes a new TimeSpan to a specified number of hours, minutes, and seconds.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public Sub New ( _
	hours As Integer, _
	minutes As Integer, _
	seconds As Integer _
)

Parameters

hours
Type: System.Int32
Number of hours.
minutes
Type: System.Int32
Number of minutes.
seconds
Type: System.Int32
Number of seconds.

ExceptionCondition
ArgumentOutOfRangeException

The parameters specify a TimeSpan value less than MinValue or greater than MaxValue.

The specified hours, minutes, and seconds are converted to ticks, and that value initializes this instance.

The following code example creates several TimeSpan objects using the constructor overload that initializes a TimeSpan to a specified number of hours, minutes, and seconds.


' Example of the TimeSpan( Integer, Integer, Integer ) constructor.

Module Example

   ' Create a TimeSpan object and display its value.
   Sub CreateTimeSpan(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal hours As Integer, ByVal minutes As Integer, _
       ByVal 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.
      outputBlock.Text &= String.Format("{0,-37}{1,16}", _
          ctor, elapsedTime.ToString()) & vbCrLf
   End Sub

   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      outputBlock.Text &= _
          "This example of the " & _
          "TimeSpan( Integer, Integer, Integer ) " & vbCrLf & _
          "constructor generates the following output." & vbCrLf & vbCrLf
      outputBlock.Text &= String.Format("{0,-37}{1,16}", "Constructor", "Value") & vbCrLf
      outputBlock.Text &= String.Format("{0,-37}{1,16}", "-----------", "-----") & vbCrLf

      CreateTimeSpan(outputBlock, 10, 20, 30)
      CreateTimeSpan(outputBlock, -10, 20, 30)
      CreateTimeSpan(outputBlock, 0, 0, 37230)
      CreateTimeSpan(outputBlock, 1000, 2000, 3000)
      CreateTimeSpan(outputBlock, 1000, -2000, -3000)
      CreateTimeSpan(outputBlock, 999999, 999999, 999999)
   End Sub
End Module

' This example of the TimeSpan( Integer, Integer, Integer )
' constructor generates the following output.
' 
' 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


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft