Home > front end >  Vue time filter use involving zero padding operation and avoid the year 1970
Vue time filter use involving zero padding operation and avoid the year 1970

Time:12-06

Js code in the
//time converting filter method one:
Vue. Filter (' dateFormat], (dataStr=& gt; {
//dataStr * 1000 to prevent access to the year of 1970
Var time=new Date (dataStr * 1000);
//cycle data for less than 10 in the previous zero padding
The function timeAdd0 (STR) {
If (STR & lt; 10) {
STR='0' + STR;
}
Return the STR
}
Var y=time. GetFullYear ();
Var m=time getMonth () + 1;
Var d=time. GetDate ();
Var h=time. GetHours ();
Var mm=time. GetMinutes ();
Var s=time. GetSeconds ();
Return y + '-' + timeAdd0 (m) + '-' + timeAdd0 (d) + "+ timeAdd0 (h) + ', '+ timeAdd0 (mm) +', '+ timeAdd0 (s);
})

//time converting filter method 2:
Vue. Filter (' dateFormat, function (originVal) {
Const dt=new Date (originVal * 1000)
//. PadStart (2 '0') is 0 operation
Const y=dt. GetFullYear ()
Const m=(dt, getMonth () + 1 + "). The padStart (2 '0')
Const d=(dt) getDate () + "). The padStart (2 '0')

Const hh=(dt) getHours () + "). The padStart (2 '0')
Const mm=(dt) getMinutes () + "). The padStart (2 '0')
Const ss=(dt) getSeconds () + "). The padStart (2 '0')

Return ` ${} y - ${m} - ${d} ${hh} : ${mm} : ${ss} `
})

Vue code in the
//used here is scope slot
{{scope. Row. Add_time | dateFormat}}
  • Related