Skip to content

Instantly share code, notes, and snippets.

@limdauto
Created October 4, 2014 10:38
Show Gist options
  • Save limdauto/2a23f946e2b3717beef0 to your computer and use it in GitHub Desktop.
Save limdauto/2a23f946e2b3717beef0 to your computer and use it in GitHub Desktop.
parseMilliseconds.js
function parseMilliseconds_ (timeframe) {
var now = new Date().getTime();
var milliseconds = {
'hour': 60 * 60 * 1000,
'day': 24 * 60 * 60 * 1000,
'week': 7 * 24 * 60 * 60 * 1000,
'4weeks': 4 * 7 * 24 * 60 * 60 * 1000
};
if (milliseconds[timeframe])
return now - milliseconds[timeframe];
if (timeframe === 'forever')
return 0;
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment