. 1 / * * 2 FMT is returned to the pre-format time. For example: "yyyy-MM-dd HH: mm: SS q" ==> 2019-12-17 14:15:16 4 3 "YY MM month in the first quarter q dd Day" ==> January 1, 2018 Q1 . 4 DATE a Date type . 5 * / . 6 const = dateTime (FMT, DATE) => { . 7 the let O = { . 8 "M +": date.getMonth () + 1 , . 9 "D +" : date.getDate () , 10 "H +" : date.getHours (), . 11 "m +" : date.getMinutes (), 12 is "+ S" : date.getSeconds (), "q+": Math.floor((date.getMonth() + 3) / 3), 14 "S": date.getMilliseconds() 15 }; 16 if (/(y+)/.test(fmt)) 17 fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); 18 for (let k in o) 19 if (new RegExp("(" + k + ")").test(fmt)) 20 fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); 21 return fmt; 22 }
The date and time of return method
Guess you like
Origin www.cnblogs.com/ordinary-yolanda/p/12054486.html
Recommended
Ranking