TimeSpan.op_Addition メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TimeSpan.op_Addition メソッドの意味・解説 

TimeSpan.op_Addition メソッド

指定した 2 つTimeSpan インスタンス加算します。

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

Public Shared Operator + ( _
    t1 As TimeSpan, _
    t2 As TimeSpan _
) As TimeSpan
Dim t1 As TimeSpan
Dim t2 As TimeSpan
Dim returnValue As TimeSpan

returnValue = (t1 + t2)
public static TimeSpan operator + (
    TimeSpan t1,
    TimeSpan t2
)
public:
static TimeSpan operator + (
    TimeSpan t1, 
    TimeSpan t2
)
J# では、オーバーロードされた演算子使用できません。
JScriptでは、 オーバーロードされた演算子使用できますが、新規に宣言することはできません。

パラメータ

t1

TimeSpan。

t2

TimeSpan

戻り値
t1 の値と t2 の値の合計を値とする TimeSpan

例外例外
例外種類条件

OverflowException

結果として得られる TimeSpan が MinValue より小さい値か、MaxValue より大きい値です。

使用例使用例

TimeSpan オブジェクト複数ペア作成し、各ペアの和を Addition 演算子計算するコード例次に示します

' Example of the TimeSpan Addition and Subtraction operators.
Imports System
Imports Microsoft.VisualBasic

Module TimeSpanAddSubOpsDemo
    
    Const dataFmt As String
 = "{0,-38}{1,24}"

    ' Pad the end of a TimeSpan string with spaces if it does not 
    ' contain milliseconds.
    Function Align( interval As TimeSpan )
 As String

        Dim intervalStr As String
 = interval.ToString( )
        Dim pointIndex  As Integer
 = intervalStr.IndexOf( ":"c )

        pointIndex = intervalStr.IndexOf( "."c, pointIndex
 )
        If pointIndex < 0 Then intervalStr
 &= "        "
        Align = intervalStr
    End Function
    
    ' Display TimeSpan parameters and their sum and difference.
    Sub ShowTimeSpanSumDiff( Left as TimeSpan,
 Right as TimeSpan )

        Console.WriteLine( )
        Console.WriteLine( dataFmt, "TimeSpan Left",
 Align( Left ) )
        Console.WriteLine( dataFmt, "TimeSpan Right",
 Align( Right ) )
        Console.WriteLine( dataFmt, _
            "TimeSpan.op_Addition( Left, Right )",
 _
            Align( TimeSpan.op_Addition( Left, Right ) ) )
        Console.WriteLine( dataFmt, _
            "TimeSpan.op_Subtraction( Left, Right )",
 _
            Align( TimeSpan.op_Subtraction( Left, Right ) ) )
    End Sub

    Sub Main( )
        Console.WriteLine( _
            "This example of the TimeSpan Addition and "
 & _
            "Subtraction " & vbCrLf & "operators
 " & _
            "generates the following output by creating "
 & vbCrLf & _
            "several pairs of TimeSpan objects and calculating
 " & _
            "and " & vbCrLf & "displaying
 the sum " & _
            "and difference of each." )

        ' Create pairs of TimeSpan objects.
        ShowTimeSpanSumDiff( _
            new TimeSpan( 1, 20, 0 ), _
            new TimeSpan( 0, 45, 10 ) )
        ShowTimeSpanSumDiff( _
            new TimeSpan( 1, 10, 20, 30, 40 ), _
            new TimeSpan( -1, 2, 3, 4, 5 ) )
        ShowTimeSpanSumDiff( _
            new TimeSpan( 182, 12, 30, 30, 505 ), _
            new TimeSpan( 182, 11, 29, 29, 495 ) )
        ShowTimeSpanSumDiff( _
            new TimeSpan( 888888888888888 ), _
            new TimeSpan( 999999999999999 ) )
    End Sub
End Module 

' This example of the TimeSpan Addition and Subtraction
' operators generates the following output by creating
' several pairs of TimeSpan objects and calculating and
' displaying the sum and difference of each.
' 
' TimeSpan Left                                 01:20:00
' TimeSpan Right                                00:45:10
' TimeSpan.op_Addition( Left, Right )           02:05:10
' TimeSpan.op_Subtraction( Left, Right )        00:34:50
' 
' TimeSpan Left                               1.10:20:30.0400000
' TimeSpan Right                               -21:56:55.9950000
' TimeSpan.op_Addition( Left, Right )           12:23:34.0450000
' TimeSpan.op_Subtraction( Left, Right )      2.08:17:26.0350000
' 
' TimeSpan Left                             182.12:30:30.5050000
' TimeSpan Right                            182.11:29:29.4950000
' TimeSpan.op_Addition( Left, Right )       365.00:00:00
' TimeSpan.op_Subtraction( Left, Right )        01:01:01.0100000
' 
' TimeSpan Left                            1028.19:21:28.8888888
' TimeSpan Right                           1157.09:46:39.9999999
' TimeSpan.op_Addition( Left, Right )      2186.05:08:08.8888887
' TimeSpan.op_Subtraction( Left, Right )   -128.14:25:11.1111111
// Example of the TimeSpan Addition and Subtraction operators.
using System;

class TimeSpanAddSubOpsDemo
{
    const string dataFmt = "{0,-18}{1,24}"
 ;

    // Pad the end of a TimeSpan string with spaces if it does not 
    // contain milliseconds.
    static string Align( TimeSpan interval
 )
    {
        string  intervalStr = interval.ToString( );
        int     pointIndex = intervalStr.IndexOf( ':' );

        pointIndex = intervalStr.IndexOf( '.', pointIndex );
        if( pointIndex < 0 ) intervalStr += "        ";
        return intervalStr;
    } 

    // Display TimeSpan parameters and their sum and difference.
    static void ShowTimeSpanSumDiff( TimeSpan
 Left, TimeSpan Right )
    {
        Console.WriteLine( );
        Console.WriteLine( dataFmt, "TimeSpan Left", Align( Left ) );
        Console.WriteLine( dataFmt, "TimeSpan Right", Align( Right ) );
        Console.WriteLine( dataFmt, "Left + Right", 
            Align( Left + Right ) );
        Console.WriteLine( dataFmt, "Left - Right", 
            Align( Left - Right ) );
    }

    static void Main( )
    {
        Console.WriteLine( "This example of the TimeSpan " +
            "Addition and Subtraction \noperators generates the " +
            "following output by creating \nseveral pairs of " +
            "TimeSpan objects and calculating and \ndisplaying " +
            "the sum and difference of each." );


        // Create pairs of TimeSpan objects.
        ShowTimeSpanSumDiff( 
            new TimeSpan( 1, 20, 0 ), 
            new TimeSpan( 0, 45, 10 ) );
        ShowTimeSpanSumDiff( 
            new TimeSpan( 1, 10, 20, 30, 40 ), 
            new TimeSpan( -1, 2, 3, 4, 5 ) );
        ShowTimeSpanSumDiff( 
            new TimeSpan( 182, 12, 30, 30, 505 ), 
            new TimeSpan( 182, 11, 29, 29, 495 ) );
        ShowTimeSpanSumDiff( 
            new TimeSpan( 888888888888888 ), 
            new TimeSpan( 999999999999999 ) );
    } 
} 

/*
This example of the TimeSpan Addition and Subtraction
operators generates the following output by creating
several pairs of TimeSpan objects and calculating and
displaying the sum and difference of each.

TimeSpan Left             01:20:00
TimeSpan Right            00:45:10
Left + Right              02:05:10
Left - Right              00:34:50

TimeSpan Left           1.10:20:30.0400000
TimeSpan Right           -21:56:55.9950000
Left + Right              12:23:34.0450000
Left - Right            2.08:17:26.0350000

TimeSpan Left         182.12:30:30.5050000
TimeSpan Right        182.11:29:29.4950000
Left + Right          365.00:00:00
Left - Right              01:01:01.0100000

TimeSpan Left        1028.19:21:28.8888888
TimeSpan Right       1157.09:46:39.9999999
Left + Right         2186.05:08:08.8888887
Left - Right         -128.14:25:11.1111111
*/ 
// Example of the TimeSpan Addition and Subtraction operators.
using namespace System;

// Pad the end of a TimeSpan string with spaces if it does not 
// contain milliseconds.
String^ Align( TimeSpan interval )
{
   String^ intervalStr = interval.ToString();
   int pointIndex = intervalStr->IndexOf( ':' );
   pointIndex = intervalStr->IndexOf( '.', pointIndex );
   if ( pointIndex < 0 )
      intervalStr = String::Concat( intervalStr, "        " );

   return intervalStr;
}


// Display TimeSpan parameters and their sum and difference.
static void ShowTimeSpanSumDiff( TimeSpan Left,
 TimeSpan Right )
{
   String^ dataFmt = "{0,-18}{1,24}";
   Console::WriteLine();
   Console::WriteLine( dataFmt, "TimeSpan Left", Align( Left ) );
   Console::WriteLine( dataFmt, "TimeSpan Right", Align( Right ) );
   Console::WriteLine( dataFmt, "Left + Right", Align( Left + Right ) );
   Console::WriteLine( dataFmt, "Left - Right", Align( Left - Right ) );
}

int main()
{
   Console::WriteLine( "This example of the TimeSpan "
   "Addition and Subtraction \noperators generates the "
   "following output by creating \nseveral pairs of "
   "TimeSpan objects and calculating and \ndisplaying "
   "the sum and difference of each." );
   
   // Create pairs of TimeSpan objects.
   ShowTimeSpanSumDiff( TimeSpan(1,20,0), TimeSpan(0,45,10) );
   ShowTimeSpanSumDiff( TimeSpan(1,10,20,30,40), TimeSpan( -1,2,3,4,5) );
   ShowTimeSpanSumDiff( TimeSpan(182,12,30,30,505), TimeSpan(182,11,29,29,495) );
   ShowTimeSpanSumDiff( TimeSpan(888888888888888), TimeSpan(999999999999999) );
}

/*
This example of the TimeSpan Addition and Subtraction
operators generates the following output by creating
several pairs of TimeSpan objects and calculating and
displaying the sum and difference of each.

TimeSpan Left             01:20:00
TimeSpan Right            00:45:10
Left + Right              02:05:10
Left - Right              00:34:50

TimeSpan Left           1.10:20:30.0400000
TimeSpan Right           -21:56:55.9950000
Left + Right              12:23:34.0450000
Left - Right            2.08:17:26.0350000

TimeSpan Left         182.12:30:30.5050000
TimeSpan Right        182.11:29:29.4950000
Left + Right          365.00:00:00
Left - Right              01:01:01.0100000

TimeSpan Left        1028.19:21:28.8888888
TimeSpan Right       1157.09:46:39.9999999
Left + Right         2186.05:08:08.8888887
Left - Right         -128.14:25:11.1111111
*/
// Example of the TimeSpan Addition and Subtraction operators.
import System.*;

class TimeSpanAddSubOpsDemo
{
    private static String dataFmt = "{0
,-18}{1,24}";

    // Pad the end of a TimeSpan string with spaces if it does not 
    // contain milliseconds.
    static String Align(TimeSpan interval)
    {
        String intervalStr = interval.ToString();
        int pointIndex = intervalStr.IndexOf(':');

        pointIndex = intervalStr.IndexOf('.', pointIndex);
        if (pointIndex < 0) {
            intervalStr += "        ";
        }
        return intervalStr;
    } //Align

    // Display TimeSpan parameters and their sum and difference.
    static void ShowTimeSpanSumDiff(TimeSpan
 Left, TimeSpan Right)
    {
        Console.WriteLine();
        Console.WriteLine(dataFmt, "TimeSpan Left", Align(Left));
        Console.WriteLine(dataFmt, "TimeSpan Right", Align(Right));
        Console.WriteLine(dataFmt, "Left + Right", Align((Right.Add(Left))));
        Console.WriteLine(dataFmt, "Left - Right",
            Align((Left.Subtract(Right))));
    } //ShowTimeSpanSumDiff

    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of the TimeSpan " 
            + "Addition and Subtraction \noperators generates the " 
            + "following output by creating \nseveral pairs of " 
            + "TimeSpan objects and calculating and \ndisplaying " 
            + "the sum and difference of each."));

        // Create pairs of TimeSpan objects.
        ShowTimeSpanSumDiff(new TimeSpan(1, 20, 0), new
 TimeSpan(0, 45, 10));
        ShowTimeSpanSumDiff(new TimeSpan(1, 10, 20, 30, 40), 
            new TimeSpan(-1, 2, 3, 4, 5));
        ShowTimeSpanSumDiff(new TimeSpan(182, 12, 30, 30, 505)
,
            new TimeSpan(182, 11, 29, 29, 495));
        ShowTimeSpanSumDiff(new TimeSpan(888888888888888L), 
            new TimeSpan(999999999999999L));
    } //main
} //TimeSpanAddSubOpsDemo

/*
This example of the TimeSpan Addition and Subtraction
operators generates the following output by creating
several pairs of TimeSpan objects and calculating and
displaying the sum and difference of each.

TimeSpan Left             01:20:00
TimeSpan Right            00:45:10
Left + Right              02:05:10
Left - Right              00:34:50

TimeSpan Left           1.10:20:30.0400000
TimeSpan Right           -21:56:55.9950000
Left + Right              12:23:34.0450000
Left - Right            2.08:17:26.0350000

TimeSpan Left         182.12:30:30.5050000
TimeSpan Right        182.11:29:29.4950000
Left + Right          365.00:00:00
Left - Right              01:01:01.0100000

TimeSpan Left        1028.19:21:28.8888888
TimeSpan Right       1157.09:46:39.9999999
Left + Right         2186.05:08:08.8888887
Left - Right         -128.14:25:11.1111111
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からTimeSpan.op_Addition メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からTimeSpan.op_Addition メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からTimeSpan.op_Addition メソッド を検索

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

辞書ショートカット

すべての辞書の索引

「TimeSpan.op_Addition メソッド」の関連用語

TimeSpan.op_Addition メソッドのお隣キーワード
検索ランキング

   

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



TimeSpan.op_Addition メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS