Free for PREMIUM members
DateTime now = DateTime.Now;
DateTime last = DateTime.Now.AddHours(-4);
Stopwatch watch = new Stopwatch();
for(int i = 0; i < 1000000; i++)
TimeSpan timeSpan = now.Subtract(last);
Stopwatch watch2 = new Stopwatch();
for (int i = 0; i < 1000000; i++)
long ticks = now.Ticks - last.Ticks;
Open in new window
public TimeSpan Subtract(DateTime value)
return new TimeSpan(this.InternalTicks - value.InternalTicks);
public DateTime Subtract(TimeSpan value)
long internalTicks = this.InternalTicks;
long num2 = value._ticks;
if ((internalTicks < num2) || ((internalTicks - 0x2bca2875f4373fffL) > num2))
throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_DateArithmetic"));
return new DateTime(((ulong) (internalTicks - num2)) | this.InternalKind);
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $12.50.
Premium members get this course for $95.20.
Premium members get this course for $159.20.
Premium members get this course for $329.00.
Premium members get this course for $79.20.
Premium members get this course for $87.50.