53

How long is a .NET DateTime/TimeSpan tick?

Jason Kresowaty
  • 16,105
  • 9
  • 57
  • 84

4 Answers4

79

Although currently a tick is 100 nanoseconds, it is best not to rely on this as an absolute. Rather, use 'TimeSpan.TicksPerSecond' (or any of the other TicksPerXxx member values)

jerryjvl
  • 19,723
  • 7
  • 40
  • 55
  • 9
    This is true. Don't hard code these in your code. However, they are absolute and will not be changed by Microsoft. The reason for this post is that sometimes one needs to do this math on a calculator and I wanted to make this chart available. – Jason Kresowaty Jun 05 '09 at 17:17
  • Example creating a 10 second timespan: `new TimeSpan(TimeSpan.TicksPerSecond * 10)` – nedstark179 May 14 '21 at 12:48
65

The tick is the unit of granularity for the .NET DateTime and TimeSpan value types.

It has the following common conversions:

1 tick = 100 nanoseconds
       = 0.1 microseconds
       = 0.0001 milliseconds
       = 0.0000001 seconds
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
Jason Kresowaty
  • 16,105
  • 9
  • 57
  • 84
  • 2
    You answered your own question one minute after posting it? – Lance McNearney Jun 05 '09 at 16:24
  • 41
    uh, StackOverflow encourages this sort of thing in the FAQ, dont down vote him for that. see: http://stackoverflow.com/questions/18557/how-does-stackoverflow-work-the-unofficial-faq#119658 – Allen Rice Jun 05 '09 at 16:46
13

To quote MSDN:

The smallest unit of time is the tick, which is equal to 100 nanoseconds.

Metrology fail.

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
8

Note that, although the theoretical resolution of DateTime.Now is quite high, the resolution - ie how often it is updated - it quite a bit lower.

Apparently, on modern systems, DateTime.Now has a resolution of 10 milliseconds... See msdn.microsoft.com/en-us/library/system.datetime.now.aspx

Community
  • 1
  • 1
utunga
  • 468
  • 5
  • 15