日期转换

85 阅读1分钟
 filters: {
  validDateFilter(val) {
    // 授权期限天数转换日期
     let date_now = new Date()
  date_now.setTime(date_now.getTime() + 24 * 60 * 60 * 1000 * (val * 1))
     let YYYY = date_now.getFullYear()
     let MM = date_now.getMonth() + 1 > 9 ? date_now.getMonth() + 1 : '0' + (date_now.getMonth() + 1)
   let DD = date_now.getDate() > 9 ? date_now.getDate() : '0' + date_now.getDate()
    return YYYY + '-' + MM + '-' + DD
  },
 },
formatDate (cellValue) {
  if (cellValue == null || cellValue == "") return "";
  var date = new Date(cellValue)
  var year = date.getFullYear()
  var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
  var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
  return year + '-' + month + '-' + day
},
formatHours (cellValue) {
  if (cellValue == null || cellValue == "") return "";
  var date = new Date(cellValue)
  var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  return hours + ':' + minutes + ':' + seconds
},