js字符串转日期

    //字符串转日期
    function stringToDate(dateStr,separator){
    	if(!dateStr){
    		return null;
    	}
        if(!separator){
               separator="-";
        }
        var dateArr = dateStr.split(separator);
        var year = parseInt(dateArr[0]);
        var month;                     
        if(dateArr[1].indexOf("0") == 0){
            month = parseInt(dateArr[1].substring(1));
        }else{
             month = parseInt(dateArr[1]);
        }
        var day = parseInt(dateArr[2]);
        var date = new Date(year,month -1,day);
        return date;
    }

 

你可能感兴趣的:(javascript,js字符串转日期)