Skip to Content
.NET Common Language Runtime Unleashed
book

.NET Common Language Runtime Unleashed

by Kevin Burton
April 2002
Intermediate to advanced content levelIntermediate to advanced
1024 pages
23h 26m
English
Sams
Content preview from .NET Common Language Runtime Unleashed

System.TimeSpan

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).

Listing B.16. TimeSpan Example
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Customizing the Microsoft® .NET Framework Common Language Runtime

Customizing the Microsoft® .NET Framework Common Language Runtime

Steven Pratschner

Publisher Resources

ISBN: 0672321246Purchase book