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.
Assembly: mscorlib (in mscorlib.dll)
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.
| Exception | Condition |
|---|---|
| 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( int, int, int, int, int ) constructor. using namespace System; // Create a TimeSpan object and display its value. void CreateTimeSpan( int days, int hours, int minutes, int seconds, int millisec ) { TimeSpan elapsedTime = TimeSpan(days,hours,minutes,seconds,millisec); // Format the constructor for display. array<Object^>^boxedParams = gcnew array<Object^>(5); boxedParams[ 0 ] = days; boxedParams[ 1 ] = hours; boxedParams[ 2 ] = minutes; boxedParams[ 3 ] = seconds; boxedParams[ 4 ] = millisec; String^ ctor = String::Format( "TimeSpan( {0}, {1}, {2}, {3}, {4} )", boxedParams ); // Display the constructor and its value. Console::WriteLine( "{0,-48}{1,24}", ctor, elapsedTime.ToString() ); } int main() { Console::WriteLine( "This example of the TimeSpan( int, int, int, int, int ) " "\nconstructor generates the following output.\n" ); 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 ); } /* This example of the TimeSpan( int, int, int, int, int ) 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 */
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1