[edit] Using the DateTime.AddTicks Method
To use the DateTime.AddTicks method you will not specify a timespan. You must specify the amount of ticks you want to add. It accepts a long value so it can NOT calculate partial ticks. Remember, a timespan must NOT be used with DateTime.AddTicks.
- Note: There are 10 million ticks in one second
In the case that microsoft changes the amount of ticks in a second you can dynamically calculate the amount of ticks in a second by using TimeSpan.
long value = TimeSpan.TicksPerSecond;
[edit] Syntax
DateTime.AddTicks(<long>)
[edit] Example 1:
using System;
class Program
{
static void Main()
{
DateTime today = DateTime.Now;
Console.WriteLine("today: " + today.ToString());
today = today.AddTicks(30000000);
Console.WriteLine("New Date: " + today.ToString());
Console.Read();
}
}
Output:
today: 4/5/2007 8:28:51 PM
New Date: 4/5/2007 8:28:54 PM
As you can see the AddTicks method simply added 3 seconds to the current date.
<-- DateTime Tutorial
|