Created
June 27, 2022 20:50
-
-
Save dkordik/c03235f03528e53da6451ada12b8f1af to your computer and use it in GitHub Desktop.
Show a date using each built-in JavaScript date format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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