I have been using C# for quite some time, and have suddenly come across DateTime.Now.Ticks.
What is it for?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It represents the total number of ticks in local time (not UTC) since the DateTime epoch, which is midnight on January 1st in the year 1AD. (Each tick is 100 nanoseconds; there are 10,000 ticks in a millisecond.)
To break it down,
DateTime.Nowis a static property returning aDateTimerepresenting the current time.Then
DateTime.Ticksis an instance property on DateTime, returning the number of ticks since midnight on January 1st, 1AD. It gets more complicated due to time zones (and DateTime’s poor design) but that’s the basics.A tick is the smallest unit of time used in
DateTimeandTimeSpan. You typically use it to make sure you can completely round-trip a value without losing any information.Note that it’s not the same thing as the ticks returned by
Stopwatch.ElapsedTicks, which are system-dependent; their length can be determined usingStopWatch.Frequency.