Get the number of ticks from DateTimeOffset object in clock time in CSharp
Description
The following code shows how to get the number of ticks from DateTimeOffset object in clock time.
Example
using System;//from ww w . jav a 2 s .c o m
public class MainClass{
public static void Main(String[] argv){
const long NSPerSecond = 10000000;
long ticks;
ticks = 7 * NSPerSecond; // Ticks in a 7 seconds
ticks += 181 * 60 * 60 * 24 * NSPerSecond; // Ticks in 6 months
ticks += 2014 * 60 * 60 * 24 * 365L * NSPerSecond; // Ticks in 2014 years
ticks += 486 * 60 * 60 * 24 * NSPerSecond; // Adjustment for leap years
DateTimeOffset dto = new DateTimeOffset(
ticks,
DateTimeOffset.Now.Offset);
Console.WriteLine("There are {0:n0} ticks in {1}.",
dto.Ticks,
dto.ToString());
}
}
The code above generates the following result.