Skip to content

Instantly share code, notes, and snippets.

@jherdman
Created March 5, 2009 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jherdman/74469 to your computer and use it in GitHub Desktop.
Save jherdman/74469 to your computer and use it in GitHub Desktop.
/*
* Extends Date to return the 24-hour clock time using 15 minute intervals for the
* minutes portion. E.x. If it is 11:04PM, this function returns 2300.
*/
Date.prototype.getInterval = function() {
var now = new Date();
var intervals = ["00", "15", "30", "45", "60"];
for(var i = 0; i < intervals.length; i++) {
var mins = now.getMinutes();
if(parseInt(intervals[i], 10) <= mins && mins <= parseInt(intervals[i + 1], 10)) {
return [now.getHours(), intervals[i]].join("");
}
}
return "000";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment