新しい TimeSpan を指定した日数、時間数、分数、秒数に初期化します。
名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文
'宣言
Public Sub New ( _
days As Integer, _
hours As Integer, _
minutes As Integer, _
seconds As Integer _
)
'使用
Dim days As Integer
Dim hours As Integer
Dim minutes As Integer
Dim seconds As Integer
Dim instance As New TimeSpan(days, hours, minutes, seconds)
public TimeSpan (
int days,
int hours,
int minutes,
int seconds
)
public:
TimeSpan (
int days,
int hours,
int minutes,
int seconds
)
public TimeSpan (
int days,
int hours,
int minutes,
int seconds
)
public function TimeSpan (
days : int,
hours : int,
minutes : int,
seconds : int
)
パラメータ
- days
日数。
- hours
時間数。
- minutes
分数。
- seconds
秒数。
例外
| 例外の種類 | 条件 |
|---|---|
解説
指定した days、hours、minutes、および seconds がタイマ刻み数に変換され、その値でこのインスタンスが初期化されます。
使用例
次に示すのは、TimeSpan を指定した日数、時間数、分数、および秒数に初期化するコンストラクタのオーバーロードを使用して、複数の TimeSpan オブジェクトを作成するコード例です。
' Example of the
' TimeSpan( Integer, Integer, Integer, Integer ) constructor.
Imports System
Imports Microsoft.VisualBasic
Module TimeSpanCtorIIIIDemo
' Create a TimeSpan object and display its value.
Sub CreateTimeSpan( days As Integer, hours As Integer, _
minutes As Integer, seconds As Integer )
Dim elapsedTime As New TimeSpan( _
days, hours, minutes, seconds )
' Format the constructor for display.
Dim ctor AS String = _
String.Format( "TimeSpan( {0}, {1}, {2}, {3} )", _
days, hours, minutes, seconds )
' Display the constructor and its value.
Console.WriteLine( "{0,-44}{1,16}", _
ctor, elapsedTime.ToString( ) )
End Sub
Sub Main( )
Console.WriteLine( _
"This example of the " & vbCrLf & "TimeSpan( " & _
"Integer, Integer, Integer, Integer ) " & vbCrLf & _
"constructor generates the following output." & vbCrLf )
Console.WriteLine( "{0,-44}{1,16}", "Constructor", "Value" )
Console.WriteLine( "{0,-44}{1,16}", "-----------", "-----" )
CreateTimeSpan( 10, 20, 30, 40 )
CreateTimeSpan( -10, 20, 30, 40 )
CreateTimeSpan( 0, 0, 0, 937840 )
CreateTimeSpan( 1000, 2000, 3000, 4000 )
CreateTimeSpan( 1000, -2000, -3000, -4000 )
CreateTimeSpan( 999999, 999999, 999999, 999999 )
End Sub
End Module
' This example of the
' TimeSpan( Integer, Integer, Integer, Integer )
' constructor generates the following output.
'
' Constructor Value
' ----------- -----
' TimeSpan( 10, 20, 30, 40 ) 10.20:30:40
' TimeSpan( -10, 20, 30, 40 ) -9.03:29:20
' TimeSpan( 0, 0, 0, 937840 ) 10.20:30:40
' TimeSpan( 1000, 2000, 3000, 4000 ) 1085.11:06:40
' TimeSpan( 1000, -2000, -3000, -4000 ) 914.12:53:20
' TimeSpan( 999999, 999999, 999999, 999999 ) 992661.08:57:23
// Example of the TimeSpan( int, int, int, int ) constructor.
using System;
class TimeSpanCtorIIIIDemo
{
// Create a TimeSpan object and display its value.
static void CreateTimeSpan( int days, int hours,
int minutes, int seconds )
{
TimeSpan elapsedTime =
new TimeSpan( days, hours, minutes, seconds );
// Format the constructor for display.
string ctor =
String.Format( "TimeSpan( {0}, {1}, {2}, {3} )",
days, hours, minutes, seconds);
// Display the constructor and its value.
Console.WriteLine( "{0,-44}{1,16}",
ctor, elapsedTime.ToString( ) );
}
static void Main( )
{
Console.WriteLine(
"This example of the TimeSpan( int, int, int, int ) " +
"\nconstructor generates the following output.\n" );
Console.WriteLine( "{0,-44}{1,16}", "Constructor", "Value" );
Console.WriteLine( "{0,-44}{1,16}", "-----------", "-----" );
CreateTimeSpan( 10, 20, 30, 40 );
CreateTimeSpan( -10, 20, 30, 40 );
CreateTimeSpan( 0, 0, 0, 937840 );
CreateTimeSpan( 1000, 2000, 3000, 4000 );
CreateTimeSpan( 1000, -2000, -3000, -4000 );
CreateTimeSpan( 999999, 999999, 999999, 999999 );
}
}
/*
This example of the TimeSpan( int, int, int, int )
constructor generates the following output.
Constructor Value
----------- -----
TimeSpan( 10, 20, 30, 40 ) 10.20:30:40
TimeSpan( -10, 20, 30, 40 ) -9.03:29:20
TimeSpan( 0, 0, 0, 937840 ) 10.20:30:40
TimeSpan( 1000, 2000, 3000, 4000 ) 1085.11:06:40
TimeSpan( 1000, -2000, -3000, -4000 ) 914.12:53:20
TimeSpan( 999999, 999999, 999999, 999999 ) 992661.08:57:23
*/
// Example of the TimeSpan( 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 )
{
TimeSpan elapsedTime = TimeSpan(days,hours,minutes,seconds);
// Format the constructor for display.
array<Object^>^boxedParams = gcnew array<Object^>(4);
boxedParams[ 0 ] = days;
boxedParams[ 1 ] = hours;
boxedParams[ 2 ] = minutes;
boxedParams[ 3 ] = seconds;
String^ ctor = String::Format( "TimeSpan( {0}, {1}, {2}, {3} )", boxedParams );
// Display the constructor and its value.
Console::WriteLine( "{0,-44}{1,16}", ctor, elapsedTime.ToString() );
}
int main()
{
Console::WriteLine( "This example of the TimeSpan( int, int, int, int ) "
"\nconstructor generates the following output.\n" );
Console::WriteLine( "{0,-44}{1,16}", "Constructor", "Value" );
Console::WriteLine( "{0,-44}{1,16}", "-----------", "-----" );
CreateTimeSpan( 10, 20, 30, 40 );
CreateTimeSpan( -10, 20, 30, 40 );
CreateTimeSpan( 0, 0, 0, 937840 );
CreateTimeSpan( 1000, 2000, 3000, 4000 );
CreateTimeSpan( 1000, -2000, -3000, -4000 );
CreateTimeSpan( 999999, 999999, 999999, 999999 );
}
/*
This example of the TimeSpan( int, int, int, int )
constructor generates the following output.
Constructor Value
----------- -----
TimeSpan( 10, 20, 30, 40 ) 10.20:30:40
TimeSpan( -10, 20, 30, 40 ) -9.03:29:20
TimeSpan( 0, 0, 0, 937840 ) 10.20:30:40
TimeSpan( 1000, 2000, 3000, 4000 ) 1085.11:06:40
TimeSpan( 1000, -2000, -3000, -4000 ) 914.12:53:20
TimeSpan( 999999, 999999, 999999, 999999 ) 992661.08:57:23
*/
// Example of the TimeSpan( int, int, int, int ) constructor.
import System.*;
class TimeSpanCtorIIIIDemo
{
// Create a TimeSpan object and display its value.
static void CreateTimeSpan(int days, int hours, int minutes, int seconds)
{
TimeSpan elapsedTime = new TimeSpan(days, hours, minutes, seconds);
// Format the constructor for display.
String ctor = String.Format("TimeSpan( {0}, {1}, {2}, {3} )",
new Object[] { (System.Int32)days, (System.Int32)hours,
(System.Int32)minutes, (System.Int32)seconds });
// Display the constructor and its value.
Console.WriteLine("{0,-44}{1,16}", ctor, elapsedTime.ToString());
} //CreateTimeSpan
public static void main(String[] args)
{
Console.WriteLine(("This example of the TimeSpan(int, int, int, int )"
+ "\nconstructor generates the following output.\n"));
Console.WriteLine("{0,-44}{1,16}", "Constructor", "Value");
Console.WriteLine("{0,-44}{1,16}", "-----------", "-----");
CreateTimeSpan(10, 20, 30, 40);
CreateTimeSpan(-10, 20, 30, 40);
CreateTimeSpan(0, 0, 0, 937840);
CreateTimeSpan(1000, 2000, 3000, 4000);
CreateTimeSpan(1000, -2000, -3000, -4000);
CreateTimeSpan(999999, 999999, 999999, 999999);
} //main
} //TimeSpanCtorIIIIDemo
/*
This example of the TimeSpan( int, int, int, int )
constructor generates the following output.
Constructor Value
----------- -----
TimeSpan( 10, 20, 30, 40 ) 10.20:30:40
TimeSpan( -10, 20, 30, 40 ) -9.03:29:20
TimeSpan( 0, 0, 0, 937840 ) 10.20:30:40
TimeSpan( 1000, 2000, 3000, 4000 ) 1085.11:06:40
TimeSpan( 1000, -2000, -3000, -4000 ) 914.12:53:20
TimeSpan( 999999, 999999, 999999, 999999 ) 992661.08:57:23
*/
プラットフォーム
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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0、1.0