Created
March 19, 2017 13:13
-
-
Save jamalnasir/fb14ae5875c3ca2b9e80c644e967fdb0 to your computer and use it in GitHub Desktop.
Adding minutes to time
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 addMinutes(time, minsToAdd) { | |
function z(n){ | |
return (n<10? '0':'') + n; | |
} | |
var bits = time.split(':'); | |
var mins = bits[0]*60 + (+bits[1]) + (+minsToAdd); | |
return z(mins%(24*60)/60 | 0) + ':' + z(mins%60); | |
} | |
addMinutes('05:40', '20'); // '06:00' | |
addMinutes('23:50', 20); // '00:10' | |
addMinutes('00:00', '120'); // '02 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment