Skip to content

Instantly share code, notes, and snippets.

@inadarei
Forked from BigBlueHat/dateToArray.js
Created October 3, 2011 23:32
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 inadarei/1260540 to your computer and use it in GitHub Desktop.
Save inadarei/1260540 to your computer and use it in GitHub Desktop.
dateToArray - handy for emitting CouchDB keys based on dates
function dateToArray(ts, length, utc) {
var length = length || 6,
d = new Date(ts),
utc = Boolean(local) || true;
if (utc) {
return [d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()].slice(0, length);
} else {
return [d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()].slice(0, length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment