Last active
November 16, 2017 16:36
-
-
Save xerosai/87eacec33d5fa94af297976013438fca to your computer and use it in GitHub Desktop.
Quick an easy date formatter for VueJS
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
/* | |
* 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