The time filter vue

// global filter, formatting time
// so-called global filter even if all instances are shared vue
Vue.filter('dateFormat' ,function(dateStr, pattern=""){
// string according to the given time, a particular time to give
  var dt = new Date(dateStr)
  //yyy---mm-dd
  var y = dt.getFullYear () // obtained Year
  var m = dt.getMonth () + 1 // to give January
  var d = dt.getDate () // Date obtained
  // return y + '-' + m + '-' + d



  if(pattern.toLowerCase() ==="yyy-mm-dd"){
    return `${y}-${m}-${d}`
  }
   else {
    var hh = dt.getHours () // obtained when
    var mm = dt.getMinutes () // points to give
    var ss = dt.getSeconds () // sec to give
    return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
   }
})
 

Guess you like

Origin www.cnblogs.com/zimoyu/p/10962999.html