TimeSpan constant
In this chapter you will learn:
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:
- Initialize a time span to 1:02:03
- Initialize a time span to 250 milliseconds
- Initialize a time span to 14 days
Home » C# Tutorial » Date, Time, TimeZone