Last active
December 11, 2019 17:58
-
-
Save xdesro/66a01101e2745ca54b63651f1be6bbaa to your computer and use it in GitHub Desktop.
Converting moment.js to vanilla JavaScript with `.toLocaleDateString()`
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
// This is meant to be a Vue component, cause my site https://henry.codes is built with Nuxt.js. I put the .js extension on there for that fresh Gist syntax highlighting. | |
export default { | |
computed: { | |
postDate() { | |
return new Date(this.post.fields.publishDate).toLocaleDateString("en-US", { month: "short", year: "2-digit" }); | |
} | |
} | |
}; |
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
import moment from 'moment'; | |
export default { | |
computed: { | |
postDate() { | |
return moment(this.post.fields.publishDate).format("MMM YY"); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment