[Vuejs]-Change display of WP REST API Date with Vue js on Laravel

0👍

The best way I can suggest is to use computed property for formatting your date. This should be something like this –

new Vue({
el: '#app',
data: {
    post : {
        //Other post data, all data pulled from Laravel API
        date: "2018-08-06T18:29:59",
        }
    },
    computed: {
       postDate() {
           var date = new Date(this.post.date);
           var month = date.getMonth() + 1;
           var day = date.getDate();
           var year = date.getFullYear();
           month = (month < 10) ? "0"+month:month;
           day = (day < 10) ? "0"+day:day;
           return day+"/"+month+"/"+year;
       }
    }
});

And in your template part

<div class="date-below"><p>created at {{postDate | date}}</p></div>

I am not aware of format string in JavaScript like PHP have. Please correct me any one who know how to use date formatting string in JavaScript.

Leave a comment