
/**
 * 跟当前时间进行比较 针对8位 yyyymmdd 字符串日期
 * @param {Object} dateStr
 * @param {Object} isGt
 */
function compareCurrentForDate8(dateStr,isGt){
	var parseResult = parseDate8(dateStr);
	
	var nowDate = new Date();  
	var nowYear = nowDate.getFullYear()
	var nowMonth = nowDate.getMonth()+1;
	var nowDate = nowDate.getDate();
	
	var yearInt = parseResult.yearInt
	var monthInt = parseResult.monthInt
	var dateInt = parseResult.dateInt
	
	if(isGt){
		if(yearInt > nowYear){
			return true;
		}
		if( yearInt == nowYear && monthInt > nowMonth){
			return true;
		}
		if( yearInt == nowYear && monthInt == nowMonth && dateInt > nowDate){
			return true;
		}
	}else{
		if(yearInt < nowYear){
			return true;
		}
		if( yearInt == nowYear && monthInt < nowMonth){
			return true;
		}
		if( yearInt == nowYear && monthInt == nowMonth && dateInt < nowDate){
			return true;
		}
	}
	
	return false;
	
	
}

/**
 * 解析时间 针对8位yyyymmdd日期
 * @param {Object} dateStr
 */
function parseDate8(dateStr){
	var yearStr=dateStr.substr(0,4);
	var yearInt = parseInt(yearStr);
	var monthStr=dateStr.substr(4,2);
	var monthInt = parseInt(monthStr);
	var dateStr=dateStr.substr(6,2);
	var dateInt = parseInt(dateStr);
	
	return {
		"yearInt":yearInt,
		"monthInt":monthInt,
		"dateInt":dateInt
	}
}

/**
 * 检查是否输入8位年月日合法
 */
function checkDate8(dateStr){
	
	if((dateStr+"").length != 8){
		return dateStr+":长度只能是8位"
	}
	
	var nowDate = new Date();  
	
	var yearStr=dateStr.substr(0,4);
	var yearInt = parseInt(yearStr);
	var monthStr=dateStr.substr(4,2);
	var monthInt = parseInt(monthStr);
	var dateStr=dateStr.substr(6,2);
	var dateInt = parseInt(dateStr);
	
	var nowYear = nowDate.getFullYear()
	var nowMonth = nowDate.getMonth()+1;
	var nowDate = nowDate.getDate();
	
	if((yearInt-nowYear)>10 || (yearInt-nowYear)<(-10)){
		return "年份输入不合法;输入年份不能(大于或小于)当前年份10年;";
	}
	if(monthInt<1 || monthInt>12){
		return "月份输入不合法;输入月份值只能是1到12之间";
	}
	var dateMax = getDateByYearAndMonth(yearInt,monthInt);
	if(dateInt<1 || dateInt>dateMax){
		return yearInt+"年"+monthInt+"月份,日期输入不合法;只能是"+1+"到"+dateMax+"之间";
	}
	return 1;
}

/**
 * 根据年份跟月份获取该月最大的日
 */
function getDateByYearAndMonth(yearValue,monthValue){
	var date = new Date(); 	
	date.setFullYear(yearValue); 	
	date.setMonth(monthValue); 	
	date.setDate(0); 	
	return date.getDate(); 
}
function fmtDate(timeStamp) {
	if(timeStamp == null){return ''}
    var date = new Date();  
    date.setTime(timeStamp);  
    var y = date.getFullYear();    
    
    var m = date.getMonth() + 1;      
    m = m < 10 ? ('0' + m) : m;    
    
    var d = date.getDate();      
    d = d < 10 ? ('0' + d) : d;  
    return y + '-' + m + '-' + d;      
};   

function fmtDate8(timeStamp) {   
	if(timeStamp == null){return ''}
    var date = new Date();  
    date.setTime(timeStamp);  
    var y = date.getFullYear();    
    
    var m = date.getMonth() + 1;      
    m = m < 10 ? ('0' + m) : m;    
    
    var d = date.getDate();      
    d = d < 10 ? ('0' + d) : d;  
    return y + '-' + m + '-' + d;      
}; 
function fmtDateTime(timeStamp) {   
	if(timeStamp == null){return ''}
    var date = new Date();  
    date.setTime(timeStamp);  
    var y = date.getFullYear();    
    
    var m = date.getMonth() + 1;      
    m = m < 10 ? ('0' + m) : m;    
    
    var d = date.getDate();      
    d = d < 10 ? ('0' + d) : d;  
    
    var h = date.getHours();    
    h = h < 10 ? ('0' + h) : h;    
    
    var minute = date.getMinutes();  
    minute = minute < 10 ? ('0' + minute) : minute;      
    
    var second = date.getSeconds();    
    second = second < 10 ? ('0' + second) : second;
    
    return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;      
};   
function fmtTimeStamp(dateStr) {   
	if(dateStr == null || dateStr==''){return ''}
    var date = new Date();  
    var dateArr=dateStr.split(' ')
    var ymd=dateArr[0].split('-')
    var hmc=dateArr[1].split('-')
    date.setFullYear(ymd[0], ymd[1]-1, ymd[2])
    date.setHours(hmc[0], hmc[1], hmc[2], 0);
    return date.getTime(); 
};   
