User-939850651 posted
Hi Uncle Vince,
To calculate the time difference between two dates and times, many people use the
TimeSpan Struct to solve it.
But if you use the TimeSpan Class, the part whose hour exceeds 23 will be converted to days by default.
Therefore, I think you have to use a string to display it. Please see the code below:
public static void Main()
{
DateTime dt = new DateTime(2020, 6, 19, 23, 11, 10);
DateTime dt2 = new DateTime(2020, 6, 20, 23, 31, 44);
TimeSpan ts = dt2.Subtract(dt);
String TimeDiff = format(ts.Days * 24 + ts.Hours)+":"+format(ts.Minutes)+":"+format(ts.Seconds);
Console.WriteLine(TimeDiff);
//DateTime dateTime = Convert.ToDateTime(TimeDiff);
//Console.WriteLine(dateTime);
Console.ReadLine();
}
public static String format(int data) {
if (data < 10) return "0" + data.ToString();
return data.ToString();
}
Result:

Hope this can help you.
Best regards,
Xudong Peng