c# - Time difference between 2 timespans fails to return expected data -
i have created 2 timespans below:
timespan currentts = timespan.fromseconds(43995); //12:13:15 timespan towtime = timespan.fromseconds(303072); //12:11:12
i'm trying find difference in minutes (by seconds i'm passing it, looks on different days). hoping around 2 minutes difference, in reality, i'm getting -57 minutes.
int timedifference = (int)currentts.subtract(towtime).minutes;
can explain doing wrong?
if looking difference between minutes (not including days, hours or seconds), can use
double timedifference = currentts.minutes - towtime.minutes; // 2
this difference of minutes component though. other people have said, these times separated 3 days, timespan possibly isn't ideal.
or, if want seconds included well, can use
timespan minutes1 = new timespan (0, currentts.minutes, currentts.seconds); timespan minutes2 = new timespan (0, towtime.minutes, towtime.seconds); double timedifference = minutes1.totalminutes - minutes2.totalminutes // 2.05;
Comments
Post a Comment