Created
October 26, 2012 09:40
-
-
Save greggy/3957865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sumup_time(t1, t2){ | |
if (t2.split(':').length == 2){ | |
t2 = '00:'+t2; | |
} | |
var d1 = new Date(0); | |
var d2 = new Date(0); | |
if (parse_time(t1).hh != '00'){ | |
d1.setHours(parse_time(t1).hh); | |
} else { | |
d1.setHours(0); | |
} | |
d1.setMinutes(parse_time(t1).mm); | |
d1.setSeconds(parse_time(t1).ss); | |
if (parse_time(t2).hh != '00'){ | |
d2.setHours(parse_time(t2).hh); | |
} | |
d2.setMinutes(parse_time(t2).mm); | |
d2.setSeconds(parse_time(t2).ss); | |
var result = d1.getTime() + d2.getTime(); | |
var newDate = new Date(result); | |
var hh = "" + newDate.getHours(); | |
var mm = "" + newDate.getMinutes(); | |
var ss = "" + newDate.getSeconds(); | |
console.log(hh, mm, ss); | |
if(hh.length < 2) hh = "0" + hh; | |
if(mm.length < 2) mm = "0" + mm; | |
if(ss.length < 2) mm = "0" + ss; | |
return {hh: hh, mm: mm, ss: ss} | |
} | |
// sumup_time('00:26:20', '01:09:17') | |
// 21 35 37 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment