TimeSpan constant

In this chapter you will learn:

  1. Zero TimeSpan value
  2. How to get value for Ticks Per Day
  3. More constants from TimeSpan

TimeSpan.Zero

The default value of TimeSpan is TimeSpan.Zero.

using System;/* j a  v a  2 s  . c  o m*/
using System.Text;
class Sample
{
    public static void Main()
    {

        Console.WriteLine(TimeSpan.Zero);
    }
}

The output:

TimeSpan.TicksPerDay

using System;// j ava  2 s  . c  om
using System.Globalization;

class MainClass {
    public static void Main() {
        // Create some date/time objects
        DateTime dt = new DateTime();
        DateTime dt1 = new DateTime(2001, 12, 31);
        DateTime dt2 = new DateTime(2000, 12, 31, 23, 59, 59);

        // Do some date time math
        DateTime today = DateTime.Today;
        today = today + new TimeSpan(TimeSpan.TicksPerDay);
        Console.WriteLine("Tomorrow is: {0}", today.ToString());
        today = DateTime.Today - new TimeSpan(7 * TimeSpan.TicksPerDay);
        Console.WriteLine("Last Week on this day it was: {0}",today.ToString());
    }
}

More constants from TimeSpan

The following code lists more constants value from TimeSpan.

using System;/*jav  a2 s  .c o  m*/

class TimeSpanFieldsDemo
{
    static void Main()
    {
        Console.WriteLine( TimeSpan.MaxValue  );
        Console.WriteLine( TimeSpan.MinValue  );
        Console.WriteLine( TimeSpan.Zero  );
        Console.WriteLine( TimeSpan.TicksPerDay );
        Console.WriteLine( TimeSpan.TicksPerHour );
        Console.WriteLine( TimeSpan.TicksPerMinute );
        Console.WriteLine( TimeSpan.TicksPerSecond );
        Console.WriteLine( TimeSpan.TicksPerMillisecond );
    }
}

Next chapter...

What you will learn in the next chapter:

  1. Initialize a time span to 1:02:03
  2. Initialize a time span to 250 milliseconds
  3. Initialize a time span to 14 days
Home » C# Tutorial » Date, Time, TimeZone
Compare DateTimeOffset
DateTimeOffset creation
Date time Value from DateTimeOffset
Compare DateTime value
DateTime constant value
DateTime constructor
DateTime properties
Create TimeSpan From
TimeSpan
TimeSpan add and subtract
DateTime and TimeSpan
Compare TimeSpan
TimeSpan constant
TimeSpan Constructor
TimeSpan Duration
TimeSpan format
Negate a TimeSpan
TimeSpan operators
Parse string to TimeSpan
TimeSpan to string
TimeSpan total properties
TimeSpan propeties
Daylight saving
Time zone ID
UTC offset with TimeZone
TimeZone converting
TimeZone creation