Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q626 How can I add two times together, 08:30 and 08:45 and get 17:15?

You are here: irt.org | FAQ | JavaScript | Date | Q626 [ previous next ]

Try:

<SCRIPT LANGUAGE="JavaScript"><!--
var t1 = '08:30', t2 = '08:45';
var m = (t1.substring(0,t1.indexOf(':'))-0) * 60 +
        (t1.substring(t1.indexOf(':')+1,t1.length)-0) +
        (t2.substring(0,t2.indexOf(':'))-0) * 60 +
        (t2.substring(t2.indexOf(':')+1,t2.length)-0);
var h = Math.floor(m / 60);
document.write(h + ':' + (m - (h * 60)));
//--></SCRIPT>

©2018 Martin Webb