First of all, sorry about my ignorance and my awful english skills, i work to improve them.So here goes my question:
I want use DateTime.Ticks (instead Guid.NewGuid) in order to calculate an identifier and a question is being raised to me. In my current culture we have 2 days on the year when we change the official time: in octuber we add an hour and in april we remove it. how does it affect to the ticks value? how ticks value is calulated? As far as i understand based on https://msdn.microsoft.com/en-us/library/system.datetime.ticks%28v=vs.110%29.aspx it seems it is not able to be a repeat value because based on the text (...)It does not include the number of ticks that are attributable to leap seconds(...) . there could be repeated ticks?, (maybe other question would be how long a tick lasts, depends on the computer? ) If i'm not wrong it cant be repeated.
Moreover, Maybe there could be a lot of stuff i misunderstand so i'm really sorry again...
Even without DST changes, you can observe DateTime.Now.Ticks
returning the same value multiple times, due to the granularity of the system clock.
But with DST changing, if you use DateTime.Now
, you will indeed see the same values repeating for one hour per year. The Ticks
property is just "the number of ticks since the DateTime
epoch, in whatever kind of value is represented". (A DateTime
value can be one of three "kinds" - universal, local, or unspecified. It's all a bit of a mess.)
If you use DateTime.UtcNow
you shouldn't see that if your system clock only moves forward... but it's entirely possible for system clocks to be changed, either manually or in an automated way, to correct them for drift. Basically, it's not a good source of uniqueness on its own.
(In terms of the length of a tick - the tick in DateTime
is always 100ns. That's not true for Stopwatch
, where you need to use the Frequency
property to find out how long a tick is, or use the Elapsed
property to just find the elapsed time as a TimeSpan
.)
See more on this question at Stackoverflow