
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
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
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
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
- Related Articles
- MySQL difference between two timestamps in Seconds?
- Difference between two timestamps in seconds in MySQL?
- Get the difference between two timestamps in seconds in MySQL?
- How to get time difference between two timestamps in seconds?
- Format TimeSpan in C#
- C# TimeSpan Min value
- C# TimeSpan Max value
- C# Program to get the difference between two dates in seconds
- Java Program to get the difference between two time zones by seconds
- C# Program to Subtract Two TimeSpan
- C# Program to Add Two TimeSpan
- What is the ratio between 50 seconds and 10 minutes?
- How to Convert Time Difference between Two Times to Number (Hours/Minutes/Seconds) in Excel?
- Difference Between & and &&
- How to convert JavaScript seconds to minutes and seconds?

Advertisements