Difference between TimeSpan Seconds() and TotalSeconds()


TimeSpan Seconds() is part of time, whereas TimeSpan TotalSeconds() converts entire time to seconds.

Let us first see the TimeSpan Seconds() method.

Example

 Live Demo

using System;
using System.Linq;
public class Demo {
   public static void Main() {
      TimeSpan ts = new TimeSpan(0, 100, 0, 20, 0);
      // seconds
      Console.WriteLine(ts.Seconds);
   }
}

Output

20

Now, let us see how TotalSeconds works for the same TimeSpan value.

Example

 Live Demo

using System;
using System.Linq;
public class Demo {
   public static void Main() {
      TimeSpan ts = new TimeSpan(0, 100, 0, 20, 0);
      // total seconds
      Console.WriteLine(ts.TotalSeconds);
   }
}

Output

360020

Now, we will see both of them in the same example.

Example

 Live Demo

using System;
using System.Linq;
public class Demo {
   public static void Main() {
      TimeSpan ts = new TimeSpan(0, 100, 0, 20, 0);
      // seconds
      Console.WriteLine(ts.Seconds);
      // total seconds
      Console.WriteLine(ts.TotalSeconds);
   }
}

Output

20
360020

Updated on: 23-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements