Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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

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

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

public TimeSpan (
	int days,
	int hours,
	int minutes,
	int seconds,
	int milliseconds
)
public TimeSpan (
	int days, 
	int hours, 
	int minutes, 
	int seconds, 
	int milliseconds
)
public function TimeSpan (
	days : int, 
	hours : int, 
	minutes : int, 
	seconds : int, 
	milliseconds : int
)

Parameters

days

Number of days.

hours

Number of hours.

minutes

Number of minutes.

seconds

Number of seconds.

milliseconds

Number of milliseconds.

Exception typeCondition

ArgumentOutOfRangeException

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

The specified days, hours, minutes, seconds, and milliseconds 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 days, hours, minutes, seconds, and milliseconds.

// Example of the TimeSpan( int, int, int, int, int ) constructor. 
using System;

class TimeSpanCtorIIIIIDemo
{
    // Create a TimeSpan object and display its value.
    static void CreateTimeSpan( int days, int hours, 
        int minutes, int seconds, int millisec )
    {
        TimeSpan elapsedTime = new TimeSpan( 
            days, hours, minutes, seconds, millisec );

        // Format the constructor for display.
        string ctor = 
            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( ) );
    }

    static void 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
*/

// Example of the TimeSpan( int, int, int, int, int ) constructor. 
import System.*;

class TimeSpanCtorIIIIIDemo
{
    // Create a TimeSpan object and display its value.
    static void CreateTimeSpan(int days, int hours, int minutes,
        int seconds, int millisec)
    {
        TimeSpan elapsedTime = new TimeSpan(days, hours, minutes, 
            seconds, millisec);

        // Format the constructor for display.
        String ctor = String.Format("TimeSpan( {0}, {1}, {2}, {3}, {4} )",
            new Object[] { (System.Int32)days, (System.Int32)hours,
            (System.Int32)minutes, (System.Int32)seconds,
            (System.Int32)millisec });

        // Display the constructor and its value.
        Console.WriteLine("{0,-48}{1,24}", ctor, elapsedTime.ToString());
    } //CreateTimeSpan

    public static void main(String[] args)
    {
        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);
    } //main
} //TimeSpanCtorIIIIIDemo

/*
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
*/

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft