Created
December 4, 2018 00:18
-
-
Save tomfordweb/8614246bce3a02c307a56692437a7b5f to your computer and use it in GitHub Desktop.
ES6 Format timestamp to locale string
This file contains 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
/** | |
* Returns a nice date, dude! | |
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString | |
* @param {string} timestamp A timestamp waiting to be parsed | |
* @pram {object} options See the link provided above | |
* @param {String} locale locale string | |
* @return {string} A formatted timestamp | |
*/ | |
export const niceDate = (timestamp, options = {}, locale = "en-US") => { | |
const mergedOptions = { | |
...{ weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }, | |
...options, | |
}; | |
return new Date(timestamp).toLocaleDateString(locale, mergedOptions); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment