In C#, DateTime.AddMilliseconds shifts a value by thousandths of a second. It is useful for timeouts, animations, and log timestamps.
One millisecond equals 10,000 ticks, and one tick is the smallest step a DateTime stores. Print milliseconds with the fff format.
This is an instance member of System.DateTime. You call it on a DateTime value, such as dt.AddMilliseconds(...). DateTime is a struct, so every value is copied and never changed in place.
Syntax
Pass the number of milliseconds to add.
C#
DateTime t = new DateTime(2026, 11, 18, 14, 30, 45);
DateTime a = t.AddMilliseconds(250); // 14:30:45.250
DateTime b = t.AddMilliseconds(1500); // 14:30:46.500
DateTime c = t.AddMilliseconds(-500); // 14:30:44.500
Call
What it does
t.AddMilliseconds(250)
A quarter of a second later.
t.AddMilliseconds(1500)
One and a half seconds later (the seconds value changes).
t.AddMilliseconds(-500)
Half a second earlier.
Format milliseconds with ToString("HH:mm:ss.fff"). Newer .NET versions keep fractions of a millisecond; older ones round to the nearest whole millisecond.
Library declarations
C#
public DateTime AddMilliseconds(double value);
Parameters
Parameter
Description
value
Required. Number of milliseconds to add. Negative values go backward.
Return Value
Return Value
Description
DateTime
A new DateTime shifted by value milliseconds, with the same Kind.
C# Examples
Example 1 — Add 250 and 1500 ms
Add milliseconds and print them with the fff pattern.
C#
using System;
using System.Globalization;
class Program {
static string Clock(DateTime d) => d.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture);
static void Main() {
DateTime t = new DateTime(2026, 11, 18, 14, 30, 45);
Console.WriteLine(Clock(t.AddMilliseconds(250)));
Console.WriteLine(Clock(t.AddMilliseconds(1500)));
}
}
Output
14:30:45.250
14:30:46.500
How It Works
Start at a whole second.t is 14:30:45 with no milliseconds.
Add 250. The milliseconds field becomes .250 and the second stays 45.
Add 1500. One full second carries over, so you get 46 seconds and .500.
fff pattern. It always prints three digits, even when the value is zero.
Example 2 — Milliseconds Are Ticks
Measure how many ticks one millisecond adds.
C#
using System;
class Program {
static void Main() {
DateTime before = new DateTime(2026, 11, 18, 14, 30, 45);
DateTime after = before.AddMilliseconds(1);
Console.WriteLine(after.Ticks - before.Ticks);
Console.WriteLine(TimeSpan.TicksPerMillisecond);
}
}
Output
10000
10000
How It Works
Two values.before and after differ by exactly one millisecond.
Ticks property.Ticks is a long count of 100-nanosecond steps.
Difference is 10000. One millisecond equals 10,000 ticks.
Constant check.TimeSpan.TicksPerMillisecond gives the same number, so you never hard-code it.
Example 3 — Build a Timeout Deadline
Create a deadline 2.5 seconds after a start time and test two moments against it.
C#
using System;
using System.Globalization;
class Program {
static string Clock(DateTime d) => d.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture);
static void Main() {
DateTime start = new DateTime(2026, 11, 18, 12, 0, 0);
DateTime deadline = start.AddMilliseconds(2500);
DateTime a = start.AddMilliseconds(1200);
DateTime b = start.AddMilliseconds(3000);
Console.WriteLine(Clock(deadline));
Console.WriteLine(a < deadline);
Console.WriteLine(b < deadline);
}
}
Output
12:00:02.500
True
False
How It Works
Set a deadline. Start at noon and allow 2500 milliseconds.
Deadline text. The value prints as 12:00:02.500, two and a half seconds after noon.
Early moment. 1200 ms is before the deadline, so the comparison prints True.
Late moment. 3000 ms is after the deadline, so the comparison prints False.
Frequently Asked Questions
There are 10,000 ticks in one millisecond (TimeSpan.TicksPerMillisecond).
The default ToString hides them. Use a format such as HH:mm:ss.fff.
Yes. A negative value moves the time earlier.
Older .NET versions round to the nearest millisecond. Newer versions keep fractional milliseconds.
No. For benchmarks use Stopwatch. DateTime is better for calendar and clock values.