TimeSpan.Duration 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
public:
TimeSpan Duration();
public TimeSpan Duration ();
member this.Duration : unit -> TimeSpan
Public Function Duration () As TimeSpan
반환
현재 TimeSpan 개체의 절대 값과 같은 값의 새 개체입니다.
예외
이 instance 값은 TimeSpan.MinValue입니다.
예제
다음 예제에서는 여러 TimeSpan 개체에 Duration 메서드를 적용합니다.
// 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.
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.
open System
let showDurationNegate (interval: TimeSpan) =
// Display the TimeSpan value and the results of the
// Duration and Negate methods.
printfn $"{interval,22}{interval.Duration(),22}{interval.Negate(),22}"
printfn "This example of TimeSpan.Duration( ), TimeSpan.Negate( ), \nand the TimeSpan Unary Negation and Unary Plus operators \ngenerates the following output.\n"
printfn "%22s%22s%22s" "TimeSpan" "Duration( )" "Negate( )"
printfn "%22s%22s%22s" "--------" "-----------" "---------"
// 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.
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
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET