TimeSpan Constructor
In this chapter you will learn:
- Initialize a time span to 1:02:03
- Initialize a time span to 250 milliseconds
- Initialize a time span to 14 days
Initialize a time span to 1:02:03
using System;//from j a v a 2 s . c o m
public class ToString
{
public static void Main()
{
TimeSpan span;
// Initialize a time span to 1:02:03.
span = new TimeSpan(1, 2, 3);
}
}
Initialize a time span to 250 milliseconds
using System;//from ja va2 s . c o m
public class ToString
{
public static void Main()
{
TimeSpan span;
// Initialize a time span to 250 milliseconds.
span = new TimeSpan(0, 0, 0, 0, 250);
}
}
Initialize a time span to 14 days
using System;/*from j a v a 2 s.co m*/
public class ToString
{
public static void Main()
{
TimeSpan span;
// Initialize a time span to 14 days.
span = new TimeSpan(-14, 0, 0, 0, 0);
}
}
The following code creates a TimeSpan representing 2.5 days.
TimeSpan timespan1 = new TimeSpan(2, 12, 0, 0); Console.WriteLine(timespan1);
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Date, Time, TimeZone