js时间戳转化为标准时间的方法

xiaoxiao2021-02-28  89

function formatTimes(code, boolean) {         var time = new Date(code)             , year = time.getFullYear()             , month = time.getMonth() + 1             , date = time.getDate()             , hour = time.getHours() < 10 ? '0' + time.getHours() : time.getHours()             , min = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes()             , sec = time.getSeconds() < 10 ? '0' + time.getSeconds() : time.getSeconds();         if (boolean) {             return year + '/' + month + '/' + date + '';         } else {             return year + '/' + month + '/' + date + '.' + hour + ':' + min + ':' + sec;         }

    }

 formatTimes(code, boolean) 

boolean 不填或者 1 可以选择时间格式

标准时间转化为时间戳直接new Date().getTime();就行了

转载请注明原文地址: https://www.6miu.com/read-37491.html

最新回复(0)