UNPKG

itheima-szy-data

Version:

``` npm install itheima-szy-data ```

18 lines (15 loc) 503 B
function dataFormat(dateStr){ const dt = new Date(dateStr) ; const y = dt.getFullYear() ; const m = padZero(dt.getMonth() + 1) const d = padZero(dt.getDate()) const hh = padZero(dt.getHours()) const mm = padZero(dt.getMinutes()) const ss = padZero(dt.getSeconds()) return `${y}-${m}-${d} ${hh}:${mm}:${ss}` } // 定义一个补零的函数 function padZero(n) { return n > 9 ? n : '0' + n } module.exports.dataFormat = dataFormat ;