Processing of back-end data timestamp in vue

method one:

      this.list.forEach(v => {
        var year = parseInt(v.created_at / (360 * 30 * 24 * 60 * 60 * 1000));
        var month = parseInt(v.created_at / (30 * 24 * 60 * 60 * 1000));
        var days = parseInt(v.created_at / (24 * 60 * 60 * 1000));
        var hour = parseInt(v.created_at / (60 * 60 * 1000)) % 24;
        var minutes = parseInt(v.created_at / (60 * 1000)) % 60;
        var seconds = parseInt(v.created_at / 1000) % 60;
        seconds = seconds < 10 ? "0" + seconds : seconds;
        v.created_at = `${days}日   ${hour}:${minutes}:${seconds}`;
      });
      console.log(res.data);

Method 2:
Use the third-party library of moment.js
1. Download:
npm install moment – ​​save
2.
Import monment from'moment'
3.

  const handelData = (data) => {
  data.map(item => {
    item.creation_date = monment(item.creation_date).format('YYYY-MM-DD hh:mm:ss')
  })
  return data
}

Guess you like

Origin blog.csdn.net/lqlq54321/article/details/107661984