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.TimeSpan(Int32, Int32, Int32) Constructor

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

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

public TimeSpan (
	int hours,
	int minutes,
	int seconds
)
public TimeSpan (
	int hours, 
	int minutes, 
	int seconds
)
public function TimeSpan (
	hours : int, 
	minutes : int, 
	seconds : int
)
Not applicable.

Parameters

hours

Number of hours.

minutes

Number of minutes.

seconds

Number of seconds.

Exception typeCondition

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( int, int, int ) constructor.
using System;

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

        // Format the constructor for display.
        string ctor = String.Format( "TimeSpan( {0}, {1}, {2} )", 
            hours, minutes, seconds);

        // Display the constructor and its value.
        Console.WriteLine( "{0,-37}{1,16}", 
            ctor, elapsedTime.ToString( ) );
    }
    
    static void Main( )
    {
        Console.WriteLine(
            "This example of the TimeSpan( int, int, int ) " +
            "\nconstructor generates the following output.\n" );
        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 );
    } 
} 

/*
This example of the TimeSpan( int, int, int )
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
*/

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

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

        // Format the constructor for display.
        String ctor = String.Format("TimeSpan( {0}, {1}, {2} )", 
            String.valueOf(hours), String.valueOf(minutes),
            String.valueOf(seconds));

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

    public static void main(String[] args)
    {
        Console.WriteLine(("This example of the TimeSpan( int, int, int ) " 
            + "\nconstructor generates the following output.\n"));
        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);
    } //main
} //TimeSpanCtorIIIDemo

/*
This example of the TimeSpan( int, int, int )
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 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

Show:
© 2014 Microsoft