Moment.js for displaying date time in Vue.js

Moment.js is a light weight java script library for data time. You can use moment.js library for validating, manipulating, parsing and displaying date and time. You can use moment.js in your code like this:

methods: {

  moment: function () {

    return moment();

  }

},

If you want to pass a date to the moment.js you can use filters as given below.

filters: {

  moment: function (date) {

    return moment(date).format('MMMM Do YYYY, h:mm:ss a');

  }

}

 

<span>{{ date | moment }}</span>

If you are using ES6 for coding import moment .

 import moment from 'moment';

If you just want to display the date and time in Vue.js 2, install moment.js using npm. The install command is:

npm install moment

<template>

  <div v-for="meta in order.meta">

    {{ getHumanDate(meta.value.date) }}

  </div>

</template>

<script>

    import moment from 'moment';

    export default {

         methods: {

            getHumanDate : function (date) {

                return moment(date, 'YYYY-MM-DD').format('DD/MM/YYYY');

            }

        }

    }

</script>