Skip to content

Instantly share code, notes, and snippets.

@egeozcan
Created May 15, 2012 12:08
Show Gist options
  • Save egeozcan/2701255 to your computer and use it in GitHub Desktop.
Save egeozcan/2701255 to your computer and use it in GitHub Desktop.
Minute difference between two arbitrary string values
function CountingMinutesI(str) {
var times = str.replace(";\"","").split("-").map(function(t) {
t = t.split(":");
var h = parseInt(t[0], 10);
var m = parseInt(t[1], 10);
var am = t[1].indexOf("am") > 0;
if(h === 12) h = 0;
var mins = m + h * 60;
if(!am) mins += 720;
return mins;
});
var diff = times[1] - times[0];
return diff > 0 ? diff : diff + 1440;
}
@egeozcan
Copy link
Author

Use it like:
CountingMinutesI("12:05am-02:55pm")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment