Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TimeSpan::Zero Field

Represents the zero TimeSpan value. This field is read-only.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
static initonly TimeSpan Zero

Because the value of the Zero field is a TimeSpan object that represents a zero time value, you can compare it with other TimeSpan objects to determine whether the latter represent positive, non-zero, or negative time intervals. You can also use this field to initialize a TimeSpan object to a zero time value.

The following example references and displays the value of the Zero field.

// Example of the TimeSpan fields. 
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;

int main()
   String^ numberFmt = "{0,-22}{1,18:N0}";
   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 ) );

   // 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

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.