标签:new 两种 时间 col tostring time() var minutes length
// 获取当前时间 var time = Date.parse(new Date()) / 1000; // 时间字符串转时间戳的两种方法 var time = ‘2020 - 06 - 30 00: 00: 00’; 1. time = new Date(Date.parse(time.replace(/-/g, "/"))).getTime() / 1000; 2. time = new Date(time).getTime() / 1000; // 时间戳转时间字符串 var time = ‘1566012105‘ let stampLength = time.toString().length let tstamp if (stampLength == 10) { tstamp = new Date(stamp * 1000) } else if (stampLength == 13) { tstamp = new Date(stamp) } else if (stampLength == 19) { tstamp = new Date(stamp) } else { console.warn(‘GetFormatTime warn: 请传入正确的时间戳‘) return } let year = tstamp.getFullYear(tstamp) let month = tstamp.getMonth(tstamp) + 1 let day = tstamp.getDate(tstamp) let hour = tstamp.getHours(tstamp) let minute = tstamp.getMinutes(tstamp) let second = tstamp.getSeconds(tstamp) if (month < 10) { month = ‘0‘ + month } if (day < 10) { day = ‘0‘ + day } if (hour < 10) { hour = ‘0‘ + hour } if (minute < 10) { minute = ‘0‘ + minute } if (second < 10) { second = ‘0‘ + second } return `${year}-${month}-${day} ${hour}:${minute}:${second}`
标签:new 两种 时间 col tostring time() var minutes length
原文地址:https://www.cnblogs.com/songmengwen1124/p/12910884.html