Calculate two time differences in C #

xiaoxiao2021-04-04  232

///

///

Calculate time interval for two dates

///

///

First date and time

///

Second date and time

///

Private

String

DatedIFF (datetime datetime1, datetime datetime2) {

String

Datediff

=

NULL

; Timespan TS1

=

New

TimeSpan (datetime1.ticks); Timespan TS2

=

New

TimeSpan (datetime2.ticks); Timespan TS

=

Ts1.subtract (TS2) .duration (); Datediff

=

Ts.days.tostring ()

"

day

"

Ts.hours.tostring ()

"

hour

"

Ts.minutes.toString ()

"

minute

"

Ts.seconds.toString ()

"

second

"

;

Return

Datediff;}

Description:

1.Datetime value type represents a specific date time between January 0:0am, January 1, 2009, 0 seconds to 59 seconds, 59 seconds, 31 December, 9999. Therefore, you can use the DateTime value type to describe any time within the imagination range. A datetime value represents a specific moment

The 2.TimeSPAN value contains many properties and methods for accessing or handling a Timespan value.

The following list covers some of them:

Add: adds another Timespan value.

Days: Returns the Timespan value calculated with the number of days.

Duration: Get absolute value of Timespan.

Hours: Returns the Timespan value calculated by hours

MilliseConds: Returns the Timespan value calculated in milliseconds.

MINUTES: Returns the Timespan value calculated by minutes.

NEGATE: Returns the opposite of the current instance.

Seconds: Returns the Timespan value calculated by second.

Subtract: Subtract another Timespan value from the medium.

Ticks: Returns the number of TIMESPAN values.

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.

转载请注明原文地址:https://www.9cbs.com/read-131840.html

New Post(0)