Skip to content

Instantly share code, notes, and snippets.

@xdesro
Last active December 11, 2019 17:58
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 xdesro/66a01101e2745ca54b63651f1be6bbaa to your computer and use it in GitHub Desktop.
Save xdesro/66a01101e2745ca54b63651f1be6bbaa to your computer and use it in GitHub Desktop.
Converting moment.js to vanilla JavaScript with `.toLocaleDateString()`
// 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" });
}
}
};
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