How long is a .NET DateTime/TimeSpan tick?
Asked Answered
F

4

53

How long is a .NET DateTime/TimeSpan tick?

Fibrosis answered 5/6, 2009 at 15:26 Comment(0)
F
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
Fibrosis answered 5/6, 2009 at 15:26 Comment(2)
You answered your own question one minute after posting it?Comradery
uh, StackOverflow encourages this sort of thing in the FAQ, dont down vote him for that. see: #19057Cobb
M
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)

Melantha answered 5/6, 2009 at 15:38 Comment(2)
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.Fibrosis
Example creating a 10 second timespan: new TimeSpan(TimeSpan.TicksPerSecond * 10)Monogenesis
F
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
Fibrosis answered 5/6, 2009 at 15:26 Comment(2)
You answered your own question one minute after posting it?Comradery
uh, StackOverflow encourages this sort of thing in the FAQ, dont down vote him for that. see: #19057Cobb
S
13

To quote MSDN:

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

Metrology fail.

Sundried answered 28/3, 2012 at 15:36 Comment(0)
H
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

Heartbreaker answered 28/1, 2011 at 0:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.