TimeSpan コンストラクタとは? わかりやすく解説

TimeSpan コンストラクタ (Int32, Int32, Int32, Int32, Int32)

新しい TimeSpan を指定した日数時間数分数、秒数、ミリ秒数に初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    days As Integer, _
    hours As Integer, _
    minutes As Integer, _
    seconds As Integer, _
    milliseconds As Integer _
)
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 TimeSpan (
    int days, 
    int hours, 
    int minutes, 
    int seconds, 
    int milliseconds
)
public function TimeSpan (
    days : int, 
    hours : int, 
    minutes : int, 
    seconds : int, 
    milliseconds : int
)

パラメータ

days

日数

hours

時間数

minutes

分数

seconds

秒数。

milliseconds

ミリ秒数。

例外例外
例外種類条件

ArgumentOutOfRangeException

パラメータに MinValue より小さいか、MaxValue より大きい TimeSpan 値が指定されています。

解説解説

dayshoursminutesseconds、および millisecondsタイマ刻み数に変換され、その値でこのインスタンス初期化されます

使用例使用例

次に示すのは、TimeSpan指定した日数時間数分数、秒数、およびミリ秒数に初期化するコンストラクタオーバーロード使用して複数TimeSpan オブジェクト作成するコード例です。

' Example of the 
' TimeSpan( Integer, Integer, Integer, Integer, Integer ) constructor.
 
Imports System
Imports Microsoft.VisualBasic

Module TimeSpanCtorIIIIIDemo

    ' Create a TimeSpan object and display its value.
    Sub CreateTimeSpan( days As Integer,
 hours As Integer, _
        minutes As Integer, seconds As
 Integer, millisec As Integer
 )

        Dim elapsedTime As New
 TimeSpan( _
            days, hours, minutes, seconds, millisec )

        ' Format the constructor for display.
        Dim ctor As String
 = _
            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( ) )
    End Sub

    Sub Main( )

        Console.WriteLine( _
            "This example of the " & vbCrLf &
 _
            "TimeSpan( Integer, Integer, " & _
            "Integer, Integer, Integer ) " & vbCrLf
 & _
            "constructor generates the following output."
 & vbCrLf )
        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 )
    End Sub 
End Module 

' This example of the
' TimeSpan( Integer, Integer, Integer, Integer, Integer )
' 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. 
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. 
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
*/
// 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
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TimeSpan コンストラクタ (Int32, Int32, Int32, Int32)

新しい TimeSpan を指定した日数時間数分数、秒数に初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

パラメータに MinValue より小さいか、MaxValue より大きい TimeSpan 値が指定されています。

解説解説
使用例使用例

次に示すのは、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
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TimeSpan コンストラクタ (Int32, Int32, Int32)

新しい TimeSpan を指定した時間数分数、秒数に初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

パラメータに MinValue より小さいか、MaxValue より大きい TimeSpan 値が指定されています。

解説解説
使用例使用例

次に示すのは、TimeSpan指定した時間数分数、および秒数に初期化するコンストラクタオーバーロード使用して複数TimeSpan オブジェクト作成するコード例です。

' Example of the TimeSpan( Integer, Integer, Integer ) constructor.
Imports System
Imports Microsoft.VisualBasic

Module TimeSpanCtorIIIDemo

    ' Create a TimeSpan object and display its value.
    Sub CreateTimeSpan( hours As Integer,
 minutes As Integer, _
        seconds As Integer )

        Dim elapsedTime As New
 TimeSpan( hours, minutes, seconds )

        ' Format the constructor for display.
        Dim ctor AS String
 = _
            String.Format( "TimeSpan( {0},
 {1}, {2} )", _
                hours, minutes, seconds )

        ' Display the constructor and its value.
        Console.WriteLine( "{0,-37}{1,16}", _
            ctor, elapsedTime.ToString( ) )
    End Sub
    
    Sub Main()

        Console.WriteLine( _
            "This example of the " & _
            "TimeSpan( Integer, Integer, Integer ) "
 & vbCrLf & _
            "constructor generates the following output."
 & vbCrLf )
        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 )
    End Sub 
End Module 

' This example of the TimeSpan( Integer, Integer, Integer )
' 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.
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.
using namespace System;

// Create a TimeSpan object and display its value.
static void CreateTimeSpan( int
 hours, int minutes, int seconds )
{
   TimeSpan elapsedTime = 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() );
}

int 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
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TimeSpan コンストラクタ

新しい TimeSpan を初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
TimeSpan (Int64) 新しTimeSpan指定したタイマ刻みの数に初期化します。

.NET Compact Framework によってサポートされています。

TimeSpan (Int32, Int32, Int32) 新しTimeSpan指定した時間数分数、秒数に初期化します。

.NET Compact Framework によってサポートされています。

TimeSpan (Int32, Int32, Int32, Int32) 新しTimeSpan指定した日数時間数分数、秒数に初期化します。

.NET Compact Framework によってサポートされています。

TimeSpan (Int32, Int32, Int32, Int32, Int32) 新しTimeSpan指定した日数時間数分数、秒数、ミリ秒数に初期化します。

.NET Compact Framework によってサポートされています。

参照参照

関連項目

TimeSpan 構造体
TimeSpan メンバ
System 名前空間
Int64 構造体

TimeSpan コンストラクタ (Int64)

新しい TimeSpan を指定したタイマ刻みの数に初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    ticks As Long _
)
Dim ticks As Long

Dim instance As New TimeSpan(ticks)
public TimeSpan (
    long ticks
)
public:
TimeSpan (
    long long ticks
)
public TimeSpan (
    long ticks
)
public function TimeSpan (
    ticks : long
)

パラメータ

ticks

100 ナノ秒単位表される期間。

使用例使用例

次に示すのは、TimeSpan指定したタイマ刻み数に初期化するコンストラクタオーバーロード使用して複数TimeSpan オブジェクト作成するコード例です。

' Example of the TimeSpan( Long ) constructor.
Imports System
Imports Microsoft.VisualBasic

Module TimeSpanCtorLDemo

    ' Create a TimeSpan object and display its value.
    Sub CreateTimeSpan( ticks As Long
 )

        Dim elapsedTime As New
 TimeSpan( ticks )

        ' Format the constructor for display.
        Dim ctor AS String
 = _
            String.Format( "TimeSpan( {0} )",
 ticks )

        ' Pad the end of a TimeSpan string with spaces if
        ' it does not contain milliseconds.
        Dim elapsedStr As String
 = elapsedTime.ToString( )
        Dim pointIndex  As Integer
 = elapsedStr.IndexOf( ":"c )

        pointIndex = elapsedStr.IndexOf( "."c, pointIndex
 )
        If pointIndex < 0 Then elapsedStr
 &= "        "

        ' Display the constructor and its value.
        Console.WriteLine( "{0,-33}{1,24}", ctor,
 elapsedStr )
    End Sub
    
    Sub Main( )

        Console.WriteLine( _
            "This example of the TimeSpan( Long ) constructor
 " & _
            vbCrLf & "generates the following output."
 & vbCrLf )
        Console.WriteLine( "{0,-33}{1,16}", "Constructor",
 "Value" )
        Console.WriteLine( "{0,-33}{1,16}", "-----------",
 "-----" )

        CreateTimeSpan( 1 )                
        CreateTimeSpan( 999999 )                
        CreateTimeSpan( -1000000000000 )        
        CreateTimeSpan( 18012202000000 )        
        CreateTimeSpan( 999999999999999999 )    
        CreateTimeSpan( 1000000000000000000 )   

    End Sub 
End Module 

' This example of the TimeSpan( Long ) constructor
' generates the following output.
' 
' Constructor                                 Value
' -----------                                 -----
' TimeSpan( 1 )                            00:00:00.0000001
' TimeSpan( 999999 )                       00:00:00.0999999
' TimeSpan( -1000000000000 )            -1.03:46:40
' TimeSpan( 18012202000000 )            20.20:20:20.2000000
' TimeSpan( 999999999999999999 )   1157407.09:46:39.9999999
' TimeSpan( 1000000000000000000 )  1157407.09:46:40
// Example of the TimeSpan( long ) constructor.
using System;

class TimeSpanCtorLDemo
{
    // Create a TimeSpan object and display its value.
    static void CreateTimeSpan( long ticks
 )
    {
        TimeSpan elapsedTime = new TimeSpan( ticks );

        // Format the constructor for display.
        string ctor = String.Format( "TimeSpan( {0} )",
 ticks );

        // Pad the end of a TimeSpan string with spaces if
        // it does not contain milliseconds.
        string  elapsedStr = elapsedTime.ToString( );
        int     pointIndex = elapsedStr.IndexOf( ':' );

        pointIndex = elapsedStr.IndexOf( '.', pointIndex );
        if( pointIndex < 0 ) elapsedStr += "        ";

        // Display the constructor and its value.
        Console.WriteLine( "{0,-33}{1,24}", ctor, elapsedStr );
    }
    
    static void Main( )
    {
        Console.WriteLine( 
            "This example of the TimeSpan( long ) constructor " +
            "\ngenerates the following output.\n" );
        Console.WriteLine( "{0,-33}{1,16}", "Constructor", "Value"
 );
        Console.WriteLine( "{0,-33}{1,16}", "-----------", "-----"
 );

        CreateTimeSpan( 1 );                
        CreateTimeSpan( 999999 );                
        CreateTimeSpan( -1000000000000 );        
        CreateTimeSpan( 18012202000000 );        
        CreateTimeSpan( 999999999999999999 );    
        CreateTimeSpan( 1000000000000000000 );   
    } 
} 

/*
This example of the TimeSpan( long ) constructor
generates the following output.

Constructor                                 Value
-----------                                 -----
TimeSpan( 1 )                            00:00:00.0000001
TimeSpan( 999999 )                       00:00:00.0999999
TimeSpan( -1000000000000 )            -1.03:46:40
TimeSpan( 18012202000000 )            20.20:20:20.2000000
TimeSpan( 999999999999999999 )   1157407.09:46:39.9999999
TimeSpan( 1000000000000000000 )  1157407.09:46:40
*/
// Example of the TimeSpan( __int64 ) constructor.
using namespace System;

// Create a TimeSpan object and display its value.
void CreateTimeSpan( __int64 ticks )
{
   TimeSpan elapsedTime = TimeSpan(ticks);
   
   // Format the constructor for display.
   String^ ctor = String::Format( "TimeSpan( {0} )", ticks );
   
   // Pad the end of a TimeSpan string with spaces if
   // it does not contain milliseconds.
   String^ elapsedStr = elapsedTime.ToString();
   int pointIndex = elapsedStr->IndexOf( ':' );
   pointIndex = elapsedStr->IndexOf( '.', pointIndex );
   if ( pointIndex < 0 )
      elapsedStr = String::Concat( elapsedStr, "        " );

   
   // Display the constructor and its value.
   Console::WriteLine( "{0,-33}{1,24}", ctor, elapsedStr );
}

int main()
{
   Console::WriteLine( "This example of the TimeSpan( __int64 ) constructor
 "
   "\ngenerates the following output.\n" );
   Console::WriteLine( "{0,-33}{1,16}", "Constructor", "Value"
 );
   Console::WriteLine( "{0,-33}{1,16}", "-----------", "-----"
 );
   CreateTimeSpan( 1 );
   CreateTimeSpan( 999999 );
   CreateTimeSpan(  -1000000000000 );
   CreateTimeSpan( 18012202000000 );
   CreateTimeSpan( 999999999999999999 );
   CreateTimeSpan( 1000000000000000000 );
}

/*
This example of the TimeSpan( __int64 ) constructor
generates the following output.

Constructor                                 Value
-----------                                 -----
TimeSpan( 1 )                            00:00:00.0000001
TimeSpan( 999999 )                       00:00:00.0999999
TimeSpan( -1000000000000 )            -1.03:46:40
TimeSpan( 18012202000000 )            20.20:20:20.2000000
TimeSpan( 999999999999999999 )   1157407.09:46:39.9999999
TimeSpan( 1000000000000000000 )  1157407.09:46:40
*/
// Example of the TimeSpan( long ) constructor.
import System.*;

class TimeSpanCtorLDemo
{
    // Create a TimeSpan object and display its value.
    static void CreateTimeSpan(long ticks)
    {
        TimeSpan elapsedTime = new TimeSpan(ticks);

        // Format the constructor for display.
        String ctor = String.Format("TimeSpan( {0} )", String.valueOf(ticks));

        // Pad the end of a TimeSpan string with spaces if
        // it does not contain milliseconds.
        String elapsedStr = elapsedTime.ToString();
        int pointIndex = elapsedStr.IndexOf(':');
        pointIndex = elapsedStr.IndexOf('.', pointIndex);
        if (pointIndex < 0) {
            elapsedStr += "        ";
        }

        // Display the constructor and its value.
        Console.WriteLine("{0,-33}{1,24}", ctor, elapsedStr);
    } //CreateTimeSPan

    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of the TimeSpan( long ) constructor
 "
            + "\ngenerates the following output.\n"));
        Console.WriteLine("{0,-33}{1,16}", "Constructor", "Value");
        Console.WriteLine("{0,-33}{1,16}", "-----------", "-----");
        CreateTimeSpan(1);
        CreateTimeSpan(999999);
        CreateTimeSpan(-1000000000000L);
        CreateTimeSpan(18012202000000L);
        CreateTimeSpan(999999999999999999L);
        CreateTimeSpan(1000000000000000000L);
    } //main
} //TimeSpanCtorLDemo

/*
This example of the TimeSpan( long ) constructor
generates the following output.

Constructor                                 Value
-----------                                 -----
TimeSpan( 1 )                            00:00:00.0000001
TimeSpan( 999999 )                       00:00:00.0999999
TimeSpan( -1000000000000 )            -1.03:46:40
TimeSpan( 18012202000000 )            20.20:20:20.2000000
TimeSpan( 999999999999999999 )   1157407.09:46:39.9999999
TimeSpan( 1000000000000000000 )  1157407.09:46:40
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「TimeSpan コンストラクタ」の関連用語

TimeSpan コンストラクタのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TimeSpan コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS