Skip to content

Instantly share code, notes, and snippets.

@xerosai
Last active November 16, 2017 16:36
Show Gist options
  • Save xerosai/87eacec33d5fa94af297976013438fca to your computer and use it in GitHub Desktop.
Save xerosai/87eacec33d5fa94af297976013438fca to your computer and use it in GitHub Desktop.
Quick an easy date formatter for VueJS
/*
* Date Format related filters that can be used anywhere (registered globally) in the project
* Import this into your main.js the root of the src directory
* */
import Vue from 'vue';
import moment from 'moment';
Vue.filter('formatToISODate', (value) => {
if (!value) return 'Specify a date to be converted';
// Date format is optional here, however, if moment.js can't convert the date, it will issue a console warning.
if (!moment(value, moment.ISO_8601).isValid()) return 'Invalid Date. Please use an ISO Date';
// The output format can be anything you'd like
return moment(value, moment.ISO_8601).format('dddd, MMMM Do YYYY');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment