TimeSpan duration = new TimeSpan(3, 30, 15); DateTime currentTime = DateTime.Now; DateTime result = currentTime.Add(duration);
DateTime date1 = new DateTime(2021, 10, 1); DateTime date2 = new DateTime(2021, 10, 15); TimeSpan difference = date2 - date1;In this code, two DateTime objects are created representing two dates. Then, the difference between the two dates is calculated using the subtraction operator, which returns a TimeSpan representing the time between the two dates. The System TimeSpan is part of the System namespace in C#, which is included in the .NET Framework Class Library.