Skip to content

Instantly share code, notes, and snippets.

@jessekinsman
Created January 24, 2015 23:59
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 jessekinsman/306a7c53a7cfe2bb0797 to your computer and use it in GitHub Desktop.
Save jessekinsman/306a7c53a7cfe2bb0797 to your computer and use it in GitHub Desktop.
Javascript function to check if time has elapsed between two dates
// lastUpdate param should be a date object or a number representing milliseconds since 1970
// interval param should be seconds
// Interval is the elapsed time you are checking
// Returns true if the interval time has elapsed
// Returns false if the interval has not elapsed
function update(lastUpdate, interval) {
var curTime = new Date().getTime();
lastUpdate = (typeof lastUpdate.getTime == "function")? lastUpdate.getTime(): lastUpdate;
interval *= 1000;
curTime -= interval;
return (lastUpdate >= curTime) ? false: true;
}
// You could do more typechecking on the lastUpdate param if you are unsure of the data you are passing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment