function getSeconds(str) { var seconds = 0; var days = str.match(/(\d+)\s*d/); var hours = str.match(/(\d+)\s*h/); var minutes = str.match(/(\d+)\s*m/); if (days) { seconds += parseInt(days[1])*86400; } if (hours) { seconds += parseInt(hours[1])*3600; } if (minutes) { seconds += parseInt(minutes[1])*60; } return seconds; }
Dominic Myers writes about all sorts of stuff to do with HTML, CSS, JavaScript and a fair chunk of self-indulgent stuff. Thoughts and opinions are all his own, and nothing to do with any employer.
Tuesday, 11 November 2014
getSeconds
This is ridiculously useful:
Labels:
JavaScript
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment