How to format simple date in vuejs2 with a filter?

0

I receive a json query object to an api, but the format I get is the following

2018-07-03T05:47:00.000Z

although I need to simply show this

2018-07-03
    
asked by Michel Novellino 03.07.2018 в 09:26
source

1 answer

0

If, like me, they have a similar case, the simplest solution is to register a filter with a split in our main.js file, which in this case would be like this

  Vue.filter('formatDate', function(value) {
  if (value) {
    return value.split("T")[0];
  }
});

When rendering, we simply use our brand-new filter

{{value.date  | formatDate }}

I hope you find it useful if you need it.

    
answered by 03.07.2018 в 09:26