TimeSpan Constructor (Int32, Int32, Int32, Int32, Int32)

Initializes a new instance of the TimeSpan structure to a specified number of days, hours, minutes, seconds, and milliseconds.

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

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

Parameters

days
Type: System.Int32

Number of days.

hours
Type: System.Int32

Number of hours.

minutes
Type: System.Int32

Number of minutes.

seconds
Type: System.Int32

Number of seconds.

milliseconds
Type: System.Int32

Number of milliseconds.

ExceptionCondition
ArgumentOutOfRangeException

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

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

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

' Example of the  
' TimeSpan( Integer, Integer, Integer, Integer, Integer ) constructor.  
Imports System
Imports Microsoft.VisualBasic

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 generates the following output. 
'  
' 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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft