工作总结

js:日期处理(处理成2012-2-28 3:28)

2019-02-16  本文已影响0人  轩轩小王子

1.Q:日期处理

A:

timingTransmissionFormat(date){

            if(!date){

                return ""

            }

            console.log('date',date) //date 1548345600000

            let finalFormatY = new Date(date).getFullYear();

            let finalFormatM = new Date(date).getMonth() + 1 < 10 ? '0' + (new Date(date).getMonth() + 1) : new Date(date).getMonth() + 1;

            let finalFormatD = new Date(date).getDate() < 10 ? '0' + (new Date(date).getDate()) : new Date(date).getDate();

            let finalFormatH = new Date(date).getHours() <10 ? '0' + (new Date(date).getHours()):new Date(date).getHours();

            let finalFormatMi =  new Date(date).getMinutes()<10 ? '0' + (new Date(date).getMinutes()):new Date(date).getMinutes();

            return finalFormatY + '-' + finalFormatM + '-' + finalFormatD + ' ' + finalFormatH + ':' + finalFormatMi

        }
上一篇 下一篇

猜你喜欢

热点阅读