To get the absolute value of time, use the TimesSpan Duration() method.
Let’s say the following is our TimeSpan.
TimeSpan ts = new TimeSpan(-7, -50, -25);
Now to get the absolute value.
TimeSpan duration = ts.Duration();
Let us see the complete code.
Example
using System;
using System.Linq;
public class Demo {
public static void Main() {
TimeSpan ts = new TimeSpan(-7, -50, -25);
TimeSpan duration = ts.Duration();
Console.WriteLine(duration);
}
}Output
07:50:25