TimeSpan.Zero フィールド
0 の TimeSpan 値を表します。このフィールドは読み取り専用です。
Public Shared ReadOnly Zero As TimeSpan
[C#]
public static readonly TimeSpan Zero;
[C++]
public: static TimeSpan Zero;
[JScript]
public static var Zero : TimeSpan;
解説
この定数は、時間の計算で 0 を使用する場合に役立ちます。
使用例
[Visual Basic, C#, C++] Zero フィールドの値を参照して表示するコード例を次に示します。
' Example of the TimeSpan fields.
Imports System
Imports Microsoft.VisualBasic
Module TimeSpanFieldsDemo
' 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
Sub Main( )
Const numberFmt As String = "{0,-22}{1,18:N0}"
Const timeFmt As String = "{0,-22}{1,26}"
Console.WriteLine( _
"This example of the fields of the TimeSpan class" & _
vbCrLf & "generates the following output." & vbCrLf )
Console.WriteLine( numberFmt, "Field", "Value" )
Console.WriteLine( numberFmt, "-----", "-----" )
' Display the maximum, minimum, and zero TimeSpan values.
Console.WriteLine( timeFmt, "Maximum TimeSpan", _
Align( TimeSpan.MaxValue ) )
Console.WriteLine( timeFmt, "Minimum TimeSpan", _
Align( TimeSpan.MinValue ) )
Console.WriteLine( timeFmt, "Zero TimeSpan", _
Align( TimeSpan.Zero ) )
Console.WriteLine( )
' Display the ticks-per-time-unit fields.
Console.WriteLine( numberFmt, "Ticks per day", _
TimeSpan.TicksPerDay )
Console.WriteLine( numberFmt, "Ticks per hour", _
TimeSpan.TicksPerHour )
Console.WriteLine( numberFmt, "Ticks per minute", _
TimeSpan.TicksPerMinute )
Console.WriteLine( numberFmt, "Ticks per second", _
TimeSpan.TicksPerSecond )
Console.WriteLine( numberFmt, "Ticks per millisecond", _
TimeSpan.TicksPerMillisecond )
End Sub
End Module
' This example of the fields of the TimeSpan class
' generates the following output.
'
' Field Value
' ----- -----
' Maximum TimeSpan 10675199.02:48:05.4775807
' Minimum TimeSpan -10675199.02:48:05.4775808
' Zero TimeSpan 00:00:00
'
' Ticks per day 864,000,000,000
' Ticks per hour 36,000,000,000
' Ticks per minute 600,000,000
' Ticks per second 10,000,000
' Ticks per millisecond 10,000
[C#]
// Example of the TimeSpan fields.
using System;
class TimeSpanFieldsDemo
{
// 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;
}
static void Main( )
{
const string numberFmt = "{0,-22}{1,18:N0}" ;
const string timeFmt = "{0,-22}{1,26}" ;
Console.WriteLine(
"This example of the fields of the TimeSpan class" +
"\ngenerates the following output.\n" );
Console.WriteLine( numberFmt, "Field", "Value" );
Console.WriteLine( numberFmt, "-----", "-----" );
// Display the maximum, minimum, and zero TimeSpan values.
Console.WriteLine( timeFmt, "Maximum TimeSpan",
Align( TimeSpan.MaxValue ) );
Console.WriteLine( timeFmt, "Minimum TimeSpan",
Align( TimeSpan.MinValue ) );
Console.WriteLine( timeFmt, "Zero TimeSpan",
Align( TimeSpan.Zero ) );
Console.WriteLine( );
// Display the ticks-per-time-unit fields.
Console.WriteLine( numberFmt, "Ticks per day",
TimeSpan.TicksPerDay );
Console.WriteLine( numberFmt, "Ticks per hour",
TimeSpan.TicksPerHour );
Console.WriteLine( numberFmt, "Ticks per minute",
TimeSpan.TicksPerMinute );
Console.WriteLine( numberFmt, "Ticks per second",
TimeSpan.TicksPerSecond );
Console.WriteLine( numberFmt, "Ticks per millisecond",
TimeSpan.TicksPerMillisecond );
}
}
/*
This example of the fields of the TimeSpan class
generates the following output.
Field Value
----- -----
Maximum TimeSpan 10675199.02:48:05.4775807
Minimum TimeSpan -10675199.02:48:05.4775808
Zero TimeSpan 00:00:00
Ticks per day 864,000,000,000
Ticks per hour 36,000,000,000
Ticks per minute 600,000,000
Ticks per second 10,000,000
Ticks per millisecond 10,000
*/
[C++]
// Example of the TimeSpan fields.
#using <mscorlib.dll>
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, S" " );
return intervalStr;
}
void main( )
{
String* numberFmt = S"{0,-22}{1,18:N0}" ;
String* timeFmt = S"{0,-22}{1,26}" ;
Console::WriteLine(
S"This example of the fields of the TimeSpan class"
S"\ngenerates the following output.\n" );
Console::WriteLine( numberFmt, S"Field", S"Value" );
Console::WriteLine( numberFmt, S"-----", S"-----" );
// Display the maximum, minimum, and zero TimeSpan values.
Console::WriteLine( timeFmt, S"Maximum TimeSpan",
Align( TimeSpan::MaxValue ) );
Console::WriteLine( timeFmt, S"Minimum TimeSpan",
Align( TimeSpan::MinValue ) );
Console::WriteLine( timeFmt, S"Zero TimeSpan",
Align( TimeSpan::Zero ) );
Console::WriteLine( );
// Display the ticks-per-time-unit fields.
Console::WriteLine( numberFmt, S"Ticks per day",
__box( TimeSpan::TicksPerDay ) );
Console::WriteLine( numberFmt, S"Ticks per hour",
__box( TimeSpan::TicksPerHour ) );
Console::WriteLine( numberFmt, S"Ticks per minute",
__box( TimeSpan::TicksPerMinute ) );
Console::WriteLine( numberFmt, S"Ticks per second",
__box( TimeSpan::TicksPerSecond ) );
Console::WriteLine( numberFmt, S"Ticks per millisecond",
__box( TimeSpan::TicksPerMillisecond ) );
}
/*
This example of the fields of the TimeSpan class
generates the following output.
Field Value
----- -----
Maximum TimeSpan 10675199.02:48:05.4775807
Minimum TimeSpan -10675199.02:48:05.4775808
Zero TimeSpan 00:00:00
Ticks per day 864,000,000,000
Ticks per hour 36,000,000,000
Ticks per minute 600,000,000
Ticks per second 10,000,000
Ticks per millisecond 10,000
*/
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard