Skip to content

Instantly share code, notes, and snippets.

@dkordik
Created June 27, 2022 20:50
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 dkordik/c03235f03528e53da6451ada12b8f1af to your computer and use it in GitHub Desktop.
Save dkordik/c03235f03528e53da6451ada12b8f1af to your computer and use it in GitHub Desktop.
Show a date using each built-in JavaScript date format
const date = new Date("2022-06-27T00:49:00Z");
// yoinked from https://flaviocopes.com/how-to-list-object-methods-javascript/
const getMethods = (obj) => {
let properties = new Set()
let currentObj = obj
do {
Object.getOwnPropertyNames(currentObj).map(item => properties.add(item))
} while ((currentObj = Object.getPrototypeOf(currentObj)))
return [...properties.keys()].filter(item => typeof obj[item] === 'function')
}
getMethods(date).forEach(method => {
method.substring(0,2) === "to" && console.log(`[${method}]`, date[method]());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment