Is it possible to do the below c#
logic in javascript
or jquery
, The code converts duration between two dates int hours,minutes and seconds.the duration 20/01/2017 00:00:00 to 20/01/2017 02:20:30 will be 26:20:30
This about converting to hh:mm:ss format hours can go beyond 24, if minutes are more than 59 it should add to hours and seconds more than 59 should add to hours.
public static string ToTimeFormat(bool includeSeconds = false)
{
var startDate = DateTime.parse("20/01/2017 00:00:00";
var endDate = DateTime.parse("20/01/2017 02:20:30");
var ts = endDate - startDate;
var totalDaysToHours = ts.Days * 24;
return string.Format("{0}:{1}", (ts.Hours + totalDaysToHours).ToString("0"),
ts.Minutes.ToString("D2"))
+ (includeSeconds ? ":" + ts.Seconds.ToString("D2") : string.Empty);
}