原生js时间戳解析成带小时

clearDate (date, hourType) {
    date = new Date(date)
    let Month;
    let Dates;
    Month = (date.getMonth() + 1).toString().length < 2 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1);
    Dates = date.getDate().toString().length < 2 ? '0' + date.getDate() : date.getDate()
    let hour = date.getHours();
    hour = hour.toString().length < 2 ? '0' + hour : hour;
    let minute = date.getMinutes();
    minute = minute.toString().length < 2 ? '0' + minute : minute;
    let seconds = date.getSeconds();
    seconds = seconds.toString().length < 2 ? '0' + seconds : seconds;
    switch (hourType) {
        case 'hour':
            return date.getFullYear() + '-' + Month + '-' + Dates + ' ' + hour + ':' + minute;
            break
        case 'seconds':
            return date.getFullYear() + '-' + Month + '-' + Dates + ' ' + hour + ':' + minute + ':' + seconds;
            break
        default:
            return date.getFullYear() + '-' + Month + '-' + Dates;
    }
},

你可能感兴趣的:(前端,原生js时间戳解析)