Get the App
SLTechnology News&Howtos  ›  Development  › 

C # how to calculate the key points of time difference

Shulou Source: shulou.com Published: 2022-06-02 09:11:19 09月28日 Update

This article mainly shows you "how to calculate the key point of time difference in c #". The content is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to calculate the time difference in c #".

C # key points of calculating time difference:

Application of C # calculating time difference function TimeSpan

The TimeSpan value contains a number of properties and methods for accessing or processing a timespan value

The following list covers some of them:

Add: added to another timespan value.

Days: returns the timespan value calculated in days.

Duration: gets the absolute value of TimeSpan.

Hours: returns the timespan value calculated in hours

Milliseconds: returns the timespan value in milliseconds.

Minutes: returns the timespan value calculated in minutes.

Negate: returns the opposite number of the current instance.

Seconds: returns the timespan value calculated in seconds.

Subtract: subtracts another timespan value from it.

Ticks: returns the number of tick of the timespan value.

TotalDays: returns the number of days represented by the timespan value.

TotalHours: returns the number of hours represented by the timespan value.

TotalMilliseconds: returns the number of milliseconds represented by the timespan value.

TotalMinutes: returns the number of minutes represented by the timespan value.

TotalSeconds: returns the number of seconds represented by the timespan value.

C # implementation method of calculating time difference:

DateTime DateTime1, DateTime2 = DateTime.Now; / / now time DateTime1 = Convert.ToDateTime ("2009-04-24 20:00:00"); / / set the required minus time string dateDiff = null; TimeSpan ts1 = new TimeSpan (DateTime1.Ticks); TimeSpan ts2 = new TimeSpan (DateTime2.Ticks); TimeSpan ts = ts1.Subtract (ts2). Duration () / / display time dateDiff = ts.Days.ToString () + "days" + ts.Hours.ToString () + "hours" + ts.Minutes.ToString () + "minutes" + ts.Seconds.ToString () + "seconds" These are all the contents of the article "how to calculate the time difference in c #". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Time time difference centering focus content hours articles days methods Learning help from functions instances hours Properties easy to understand more organized present tense Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia MySQL OPPO Reno Microsoft