Add milliseconds to DateTime
using System;
using System.Globalization;
class Sample
{
public static void Main()
{
string dateFormat = "MM/dd/yyyy hh:mm:ss.fffffff";
DateTime date1 = new DateTime(1999, 2, 2, 16, 0, 0);
Console.WriteLine("Original date: {0} ({1:N0} ticks)",date1.ToString(dateFormat), date1.Ticks);
DateTime date2 = date1.AddMilliseconds(1);
Console.WriteLine("Second date: {0} ({1:N0} ticks)",date2.ToString(dateFormat), date2.Ticks);
Console.WriteLine("Difference between dates: {0} ({1:N0} ticks)",date2 - date1, date2.Ticks - date1.Ticks);
}
}
/*
Original date: 02/02/1999 04:00:00.0000000 (630,535,680,000,000,000 ticks)
Second date: 02/02/1999 04:00:00.0010000 (630,535,680,000,010,000 ticks)
Difference between dates: 00:00:00.0010000 (10,000 ticks)
*/
Related examples in the same category