
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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# difference in milliseconds between two DateTime
Let’s say the following are two DateTime objects for our dates.
DateTime date1 = new DateTime(2018, 8, 11, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 11, 11, 14, 25);
Find the difference between both these dates using TimeSpan.
TimeSpan ts = date2 - date1;
Now to get the Milliseconds, use the following property −
ts.TotalMilliseconds
Let us see the complete code.
Example
using System; using System.Linq; public class Demo { public static void Main() { DateTime date1 = new DateTime(2018, 8, 11, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 11, 11, 14, 25); TimeSpan ts = date2 - date1; Console.WriteLine("No. of Seconds (Difference) = {0}", ts.TotalMilliseconds); } }
Output
No. of Seconds (Difference) = 10745000
- Related Questions & Answers
- Find the difference between two datetime values with MySQL?
- Difference between datetime and datetime-local in HTML5
- Java Program to get Milliseconds between two time instants
- How to convert Python DateTime string into integer milliseconds?
- Difference between two given time periods in C++
- Find difference between sums of two diagonals in C++.
- Find minimum difference between any two element in C++
- Find the compatibility difference between two arrays in C++
- Difference between two strings JavaScript
- Difference between two selects in MySQL?
- C# program to list the difference between two lists
- C# Program to get the difference between two dates
- C# Program to return the difference between two sequences
- C++ Program to Calculate Difference Between Two Time Period
- Maximum difference between two subsets of m elements in C
Advertisements