js把毫秒值转换成时间格式yyyy-mm-dd 字符串格式与时间互转

//str是毫秒值字符串
//把毫秒值解析成时间格式
function getMyDate(str) {
	    var oDate = new Date(str),
	    oYear = oDate.getFullYear(),
	    oMonth = oDate.getMonth()+1,
	    oDay = oDate.getDate(),
	    oHour = oDate.getHours(),
	    oMin = oDate.getMinutes(),
	    oSen = oDate.getSeconds(),
	    oTime = oYear +'-'+ addZero(oMonth) +'-'+ addZero(oDay);
	    return oTime;
	}

	//补零操作
	function addZero(num){
	    if(parseInt(num) < 10){
	        num = '0'+num;
	    }
	    return num;
	}

输出的格式是yyyy-mm-dd


    //把时间格式yyyy-mm-dd字符串转换为时间date
    loanDate = loanDate.replace(new RegExp("-","gm"),"/");
    //把date转换成毫秒值
	var starttimeHaoMiao = (new Date(loanDate)).getTime()

你可能感兴趣的:(js,js)