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

TimeSpan.Duration メソッド

値が現在の TimeSpan オブジェクト絶対値である、新しTimeSpan オブジェクト返します

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

Dim instance As TimeSpan
Dim returnValue As TimeSpan

returnValue = instance.Duration
public TimeSpan Duration ()
public:
TimeSpan Duration ()
public TimeSpan Duration ()

戻り値
値が現在の TimeSpan オブジェクト絶対値である新しTimeSpan

例外例外
例外種類条件

OverflowException

このインスタンスの値が、MinValue です。

使用例使用例

複数TimeSpan オブジェクトDuration メソッド適用するコード例次に示します

' Example of the TimeSpan.Duration( ) and TimeSpan.Negate( ) methods
,
' and the TimeSpan Unary Negation and Unary Plus operators.
Imports System
Imports Microsoft.VisualBasic

Module DuraNegaUnaryDemo

    Const dataFmt As String
 = "{0,22}{1,22}{2,22}"

    Sub ShowDurationNegate( interval As TimeSpan
 )

        ' Display the TimeSpan value and the results of the 
        ' Duration and Negate methods.
        Console.WriteLine( dataFmt, _
            interval, interval.Duration( ), interval.Negate( ) )
    End Sub

    Sub Main( )

        Console.WriteLine( _
            "This example of TimeSpan.Duration( ), "
 & _
            "TimeSpan.Negate( ), " & vbCrLf &
 _
            "and the TimeSpan Unary Negation and "
 & _
            "Unary Plus operators " & vbCrLf &
 _
            "generates the following output." &
 vbCrLf )
        Console.WriteLine( dataFmt, _
            "TimeSpan", "Duration(
 )", "Negate( )" )    
        Console.WriteLine( dataFmt, _
            "--------", "-----------",
 "---------" )    

        ' Create TimeSpan objects and apply the Unary Negation
        ' and Unary Plus operators to them.
        ShowDurationNegate( new TimeSpan( 1 ) )
        ShowDurationNegate( new TimeSpan( -1234567 ) )
        ShowDurationNegate( TimeSpan.op_UnaryPlus( _
            new TimeSpan( 0, 0, 10, -20, -30 ) ) )
        ShowDurationNegate( TimeSpan.op_UnaryPlus( _
            new TimeSpan( 0, -10, 20, -30, 40 ) ) )
        ShowDurationNegate( TimeSpan.op_UnaryNegation( _
            new TimeSpan( 1, 10, 20, 40, 160 ) ) )
        ShowDurationNegate( TimeSpan.op_UnaryNegation( _
            new TimeSpan( -10, -20, -30, -40, -50 ) ) )
    End Sub 
End Module 

' This example of TimeSpan.Duration( ), TimeSpan.Negate( ),
' and the TimeSpan Unary Negation and Unary Plus operators
' generates the following output.
' 
'               TimeSpan           Duration( )             Negate( )
'               --------           -----------             ---------
'       00:00:00.0000001      00:00:00.0000001     -00:00:00.0000001
'      -00:00:00.1234567      00:00:00.1234567      00:00:00.1234567
'       00:09:39.9700000      00:09:39.9700000     -00:09:39.9700000
'      -09:40:29.9600000      09:40:29.9600000      09:40:29.9600000
'    -1.10:20:40.1600000    1.10:20:40.1600000    1.10:20:40.1600000
'    10.20:30:40.0500000   10.20:30:40.0500000  -10.20:30:40.0500000
// Example of the TimeSpan.Duration( ) and TimeSpan.Negate( ) methods
,
// and the TimeSpan Unary Negation and Unary Plus operators.
using System;

class DuraNegaUnaryDemo
{
    const string dataFmt = "{0,22}{1,22}{2,22}"
 ;

    static void ShowDurationNegate( TimeSpan
 interval )
    {
        // Display the TimeSpan value and the results of the 
        // Duration and Negate methods.
        Console.WriteLine( dataFmt, 
            interval, interval.Duration( ), interval.Negate( ) );
    }

    static void Main()
    {
        Console.WriteLine(
            "This example of TimeSpan.Duration( ), " +
            "TimeSpan.Negate( ), \nand the TimeSpan Unary " +
            "Negation and Unary Plus operators \n" +
            "generates the following output.\n" );
        Console.WriteLine( dataFmt, 
            "TimeSpan", "Duration( )", "Negate( )"
 );
        Console.WriteLine( dataFmt, 
            "--------", "-----------", "---------"
 );

        // Create TimeSpan objects and apply the Unary Negation
        // and Unary Plus operators to them.
        ShowDurationNegate( new TimeSpan( 1 ) );
        ShowDurationNegate( new TimeSpan( -1234567 ) );
        ShowDurationNegate( 
            + new TimeSpan( 0, 0, 10, -20, -30 ) );
        ShowDurationNegate( 
            + new TimeSpan( 0, -10, 20, -30, 40 ) );
        ShowDurationNegate( 
            - new TimeSpan( 1, 10, 20, 40, 160 ) );
        ShowDurationNegate( 
            - new TimeSpan( -10, -20, -30, -40, -50 ) );
    } 
} 

/*
This example of TimeSpan.Duration( ), TimeSpan.Negate( ),
and the TimeSpan Unary Negation and Unary Plus operators
generates the following output.

              TimeSpan           Duration( )             Negate( )
              --------           -----------             ---------
      00:00:00.0000001      00:00:00.0000001     -00:00:00.0000001
     -00:00:00.1234567      00:00:00.1234567      00:00:00.1234567
      00:09:39.9700000      00:09:39.9700000     -00:09:39.9700000
     -09:40:29.9600000      09:40:29.9600000      09:40:29.9600000
   -1.10:20:40.1600000    1.10:20:40.1600000    1.10:20:40.1600000
   10.20:30:40.0500000   10.20:30:40.0500000  -10.20:30:40.0500000
*/ 
// Example of the TimeSpan::Duration( ) and TimeSpan::Negate( ) methods
,
// and the TimeSpan Unary Negation and Unary Plus operators.
using namespace System;
const __wchar_t * protoFmt = L"{0,22}{1,22}{2,22}";
void ShowDurationNegate( TimeSpan interval )
{
   
   // Display the TimeSpan value and the results of the 
   // Duration and Negate methods.
   Console::WriteLine( gcnew String( protoFmt ), interval, interval.Duration(), interval.Negate()
 );
}

int main()
{
   Console::WriteLine( "This example of TimeSpan::Duration( ), "
   "TimeSpan::Negate( ), \nand the TimeSpan Unary "
   "Negation and Unary Plus operators \n"
   "generates the following output.\n" );
   Console::WriteLine( gcnew String( protoFmt ), "TimeSpan", "Duration(
 )", "Negate( )" );
   Console::WriteLine( gcnew String( protoFmt ), "--------", "-----------",
 "---------" );
   
   // Create TimeSpan objects and apply the Unary Negation
   // and Unary Plus operators to them.
   ShowDurationNegate( TimeSpan(1) );
   ShowDurationNegate( TimeSpan( -1234567) );
   ShowDurationNegate(  +TimeSpan(0,0,10,-20,-30) );
   ShowDurationNegate(  +TimeSpan(0,-10,20,-30,40) );
   ShowDurationNegate(  -TimeSpan(1,10,20,40,160) );
   ShowDurationNegate(  -TimeSpan( -10,-20,-30,-40,-50) );
}

/*
This example of TimeSpan::Duration( ), TimeSpan::Negate( ),
and the TimeSpan Unary Negation and Unary Plus operators
generates the following output.

              TimeSpan           Duration( )             Negate( )
              --------           -----------             ---------
      00:00:00.0000001      00:00:00.0000001     -00:00:00.0000001
     -00:00:00.1234567      00:00:00.1234567      00:00:00.1234567
      00:09:39.9700000      00:09:39.9700000     -00:09:39.9700000
     -09:40:29.9600000      09:40:29.9600000      09:40:29.9600000
   -1.10:20:40.1600000    1.10:20:40.1600000    1.10:20:40.1600000
   10.20:30:40.0500000   10.20:30:40.0500000  -10.20:30:40.0500000
*/
// Example of the TimeSpan.Duration( ) and TimeSpan.Negate( ) methods
,
// and the TimeSpan Unary Negation and Unary Plus operators.
import System.*;

class DuraNegaUnaryDemo
{
    private static String dataFmt = "{0
,22}{1,22}{2,22}";

    static void ShowDurationNegate(TimeSpan
 interval)
    {
        // Display the TimeSpan value and the results of the 
        // Duration and Negate methods.
        Console.WriteLine(dataFmt, interval, interval.Duration(),
            interval.Negate());
    } //ShowDurationNegate

    public static void main(String[]
 args)
    {
        Console.WriteLine(("This example of TimeSpan.Duration( ), " 
            + "TimeSpan.Negate( ), \nand the TimeSpan Unary " 
            + "Negation and Unary Plus operators \n" 
            + "generates the following output.\n"));
        Console.WriteLine(dataFmt, "TimeSpan", "Duration( )",
 "Negate( )");
        Console.WriteLine(dataFmt, "--------", "-----------",
 "---------");

        // Create TimeSpan objects and apply the Unary Negation
        // and Unary Plus operators to them.
        ShowDurationNegate(new TimeSpan(1));
        ShowDurationNegate(new TimeSpan(-1234567));
        ShowDurationNegate(new TimeSpan(0, 0, 10, -20, -30));
        ShowDurationNegate(new TimeSpan(0, -10, 20, -30, 40));
        ShowDurationNegate(new TimeSpan(1, 10, 20, 40, 160).Negate());
        ShowDurationNegate(new TimeSpan(-10, -20, -30, -40, -50).Negate());
    } //main
} //DuraNegaUnaryDemo

/*
This example of TimeSpan.Duration( ), TimeSpan.Negate( ),
and the TimeSpan Unary Negation and Unary Plus operators
generates the following output.

              TimeSpan           Duration( )             Negate( )
              --------           -----------             ---------
      00:00:00.0000001      00:00:00.0000001     -00:00:00.0000001
     -00:00:00.1234567      00:00:00.1234567      00:00:00.1234567
      00:09:39.9700000      00:09:39.9700000     -00:09:39.9700000
     -09:40:29.9600000      09:40:29.9600000      09:40:29.9600000
   -1.10:20:40.1600000    1.10:20:40.1600000    1.10:20:40.1600000
   10.20:30:40.0500000   10.20:30:40.0500000  -10.20:30:40.0500000
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

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

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

   

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



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

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

©2024 GRAS Group, Inc.RSS