原生js封装时间过滤函数

原生js封装时间过滤函数

function format(time) {
                let date = new Date(time);
                let y = date.getFullYear();
                let m = (date.getMonth() + 1 + '').padStart(2, '0');
                let d = (date.getDate() + '').padStart(2, '0');
                let hh = (date.getHours() + '').padStart(2, '0');
                let mm = (date.getMinutes() + '').padStart(2, '0');
                let ss = (date.getSeconds() + '').padStart(2, '0');

                return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
            }

你可能感兴趣的:(前端)