Javascript create/parse TimeSpan

Date: 2020-07-16
 function parseTimeSpanSeconds(timespanStr) {
	var m = /(\d+):(\d+):(\d+)/.exec(timespanStr);
	if (!m) { return 0; }
	return (parseInt(m[1]) * 3600) + (parseInt(m[2]) * 60) + parseInt(m[3]);
}

function secondsToTimeSpan(totalSeconds) {
	var hours = Math.floor(totalSeconds / 3600);
	totalSeconds -= (hours * 3600);
	var minutes = Math.floor(totalSeconds / 60);
	totalSeconds -= (minutes * 60);
	var seconds = Math.floor(totalSeconds);
	return [hours, minutes, seconds].map(e => String(e).padStart(2, "0")).join(":");
}

// secondsToTimeSpan(500763)
// "139:06:03"
// parseTimeSpanSeconds("139:06:03")
// 500763

38410cookie-checkJavascript create/parse TimeSpan