Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to Subtract Two TimeSpan
Firstly, set two TimeSpans −
TimeSpan t1 = TimeSpan.FromMinutes(2); TimeSpan t2 = TimeSpan.FromMinutes(1);
To add it, use the Subtract() method −
imeSpan res = t1.Subtract(t2);
Here is the complete code −
Example
using System;
using System.Linq;
public class Demo {
public static void Main() {
TimeSpan t1 = TimeSpan.FromMinutes(2);
TimeSpan t2 = TimeSpan.FromMinutes(1);
Console.WriteLine("First TimeSpan: "+t1);
Console.WriteLine("Second TimeSpan: "+t2);
// Subtracting
TimeSpan res = t1.Subtract(t2);
Console.WriteLine("Resultant TimeSpan: "+res);
}
}
Output
First TimeSpan: 00:02:00 Second TimeSpan: 00:01:00 Resultant TimeSpan: 00:01:00
Advertisements