Vue front end - convert timestamp to date format/date to timestamp

1. Convert date to timestamp

new Date().getTime()  //当前时间 变成时间戳
 new Date(res.data.beginTime).getTime()  //获取到的时间转化成时间格式,再变成时间戳

2. Convert timestamp to date format
1. Installation

npm install moment --save

2. main.js injection

import moment from 'moment'
Vue.filter('dateFormat',(value,pattern = 'YYYY-MM-DD HH:mm:ss') => {  //需要什么格式,自行修改
  return moment(value).format(pattern)
})

3. Use

<el-table-column
          prop="date"
          label="Exe. Time"
        >
          <template slot-scope="scope">
            {
   
   { scope.row.date | dateFormat }}
          </template>
        </el-table-column>

end~

Guess you like

Origin blog.csdn.net/buukyjmvni/article/details/119604671