-4

In Javascript I can use var d = new Date(); var n = d.getTime(); to get the time in milliseconds. Is there any similar method in C#?

1 Answers1

5

Subtracting a DateTime from another DateTime returns a TimeSpan.

DateTime d1 = DateTime.UtcNow;
DateTime d2 = DateTime.UtcNow.AddDays(1);
TimeSpan ts = d2 - d1;
Console.WriteLine(ts.TotalMilliseconds);
// Outputs 86400000
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86