DateTime.Ticks in .NET. Its use and why is it used?

I have been using C # for some time, and suddenly stumbled upon a thing called

DateTime.Now.Ticks;

Can anyone tell what it is for?

I think it should represent a specific second or millisecond.

+4
source share
1 answer

It represents the total number of ticks in local (non) UTC time from the DateTime era, which is midnight January 1 in 1AD of the year. (Each tick is 100 nanoseconds, in milliseconds 10,000 ticks).

To break it, DateTime.Now is a static property that returns a DateTime that displays the current time.

Then, DateTime.Ticks is an instance property in DateTime, returning the number of ticks since midnight January 1, 1AD. It gets more complicated due to time zones (and poor DateTime design ), but these are the basics.

A tick is the smallest unit of time used in DateTime and TimeSpan . You usually use it to make sure that you can fully round the value without losing any information.

Please note that this is not the same as ticks returned by Stopwatch.ElapsedTicks , which are system dependent; their length can be determined using StopWatch.Frequency .

+6
source

Source: https://habr.com/ru/post/1400699/


All Articles