Skip to content

Instantly share code, notes, and snippets.

@wehrhaus
Created April 11, 2014 03:50
Show Gist options
  • Save wehrhaus/10439961 to your computer and use it in GitHub Desktop.
Save wehrhaus/10439961 to your computer and use it in GitHub Desktop.
Breakdown timestamp into useable parts.
var decomposeTimestamp = function (timestamp) {
var month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
d = new Date(timestamp),
component = {};
return component = {
day: function () { return d.getDate(); },
month: function (type) { // call month('num') for 1 thru 12 instead of Names
if (type === 'num') {
return d.getMonth() +1;
}
return month[d.getMonth()];
},
year: function () { return d.getFullYear(); }
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment