vue-cli use moment.js conversion time format YYYY Year MM Month DD Day, or YYYY-MM-DD HH: MM: SS format

1. In the introduction moment mian.js

import moment from 'moment'
Vue.prototype.$moment = 'moment'

2. Set Global filter main.js

Vue.filter ( 'Moment', function (value, the formatString) { 
  the formatString = the formatString || 'YYYY Year MM Month DD Day' ;
   // return Moment (value) .format (the formatString); // value may be an ordinary date 20,170,723 
  return moment.unix (value) .format (the formatString); // this is a spin-up time stamp 
}); 

// marked red at the custom format can also YYYY-MM-DD HH: MM : SS, or YYYY / MM / DD

 

3. Render to page

 <div>{{time | moment}}</div>

 

 

 

 

Guess you like

Origin www.cnblogs.com/panax/p/10932550.html