C# Program to get the absolute value of the time


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

 Live Demo

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

Updated on: 23-Jun-2020

717 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements