Difference between TimeSpan Seconds() and TotalSeconds()

CsharpProgrammingServer Side Programming

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
raja
Published on 12-Sep-2018 12:33:45
Advertisements