April 2002
Intermediate to advanced
1024 pages
23h 26m
English
This structure represents an interval of time. Because the number of days in months and years varies and those values change between some cultures, the longest unit of time used by TimeSpan is a day. Listing B.16 shows an example of using TimeSpan (timespan.cs).
public class TimeSpanMain
{
static void Main(string [] args)
{
// Allocate a TimeSpan object
// with a given number of ticks
TimeSpan ts = new TimeSpan(1012);
Console.WriteLine("{0} ", ts);
// Allocate a TimeSpan object
// with days, hours, minutes, seconds
ts = new TimeSpan(11, 13, 46, 40);
Console.WriteLine("{0} {1} ", ts, ts.Ticks.ToString("#,#"));
}
}
|
The output for Listing B.16 is as follows:
00:00:00.0001012 11.13:46:40 10,000,000,000,000 ...