Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function humanTimeToSeconds(timestr) {
if(timestr.indexOf(':') < 0){
return null;
}
var vals = timestr.split(':')
if(vals.length !== 2){
return null;
}
var hr = parseInt(vals[0]);
var mn = parseInt(vals[1]);
if(isNaN(hr) || isNaN(mn)){
return null;
}
return hr * 3600 + mn * 60;
}
function secondsToHumanTime(ts) {
var hr = Math.floor(ts / 3600);
var mn = Math.floor((ts - hr * 3600) / 60);
if(hr < 10){ hr = '0' + hr; }
if(mn < 10){ mn = '0' + mn; }
return hr + ':' + mn;
}
console.log(getStartTime('10:30'));
console.log(getTimestamp(37800));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.