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)

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
)

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

class Example
{
   // Create a TimeSpan object and display its value.
   static void CreateTimeSpan(System.Windows.Controls.TextBlock outputBlock, 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.
      outputBlock.Text += String.Format("{0,-37}{1,16}\n",
          ctor, elapsedTime.ToString());
   }

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text +=
          "This example of the TimeSpan( int, int, int ) " +
          "\nconstructor generates the following output.\n" + "\n";
      outputBlock.Text += String.Format("{0,-37}{1,16}", "Constructor", "Value") + "\n";
      outputBlock.Text += String.Format("{0,-37}{1,16}", "-----------", "-----") + "\n";

      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);
   }
}

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


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

Show:
© 2014 Microsoft