
/**
 * param:  "day" 表示 年-月-日 | 
 *      (默认) "time" 表示  年-月-日 时:分:秒 
 */
export function unioformDateTransform(date, param = "time"){
    if(date){
        let strDate = new Date(date).toLocaleString('zh-CN')
        let days = strDate.split(" ")[0]
        let time = strDate.split(" ")[1]
        let year = days.split("/")[0]
        let month = days.split("/")[1]
        let day = days.split("/")[2]

        if(Number(month)<10){
            month = '0'+ month
        }
        if(Number(day)<10){
            day = '0'+day
        }
        days =  year+'-'+month+'-'+day

        switch(param){
            case "day":
                return days
            case "time":
                return days + " " + time
        }
    }else{
        return ''
    }
}


// 时间戳 转换成 天/时/分/秒
export function TimestampToDate(timestamp){
    let remainStamp = timestamp
    let day = 0
    let hours = 0
    let minutes  = 0
    let seconds = 0

    day = Math.floor(remainStamp / 1000 / 60 /60 / 24 )
    remainStamp = remainStamp - day * 24 * 60 * 60 *1000

    hours = Math.floor(remainStamp / 1000 / 60 / 60) 
    remainStamp = remainStamp - hours * 60 * 60 * 1000

    minutes = Math.floor(remainStamp / 1000 / 60)
    remainStamp = remainStamp - minutes * 1000 * 60

    seconds = Math.floor(remainStamp / 1000)

    return {
        day,
        hours,
        minutes,
        seconds
    }
}

// 时:分:秒  ——>>  秒
export function TimeToSecond(time){
    let splitArr = time.split(':')
    let hour = splitArr[0]
    let minute = splitArr[1]
    let seconds = splitArr[2]
    return seconds + minute * 60 + hour * 60 * 60
}