Date.prototype.format = function(formatStr) {
	var str = formatStr;
	var Week = ['日', '一', '二', '三', '四', '五', '六'];

	str = str.replace(/yyyy|YYYY/, this.getFullYear());
	str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100));

	str = str.replace(/MM/, this.getMonth() > 8 ? (this.getMonth() + 1).toString() : '0' + (this.getMonth() + 1));
	str = str.replace(/M/g, this.getMonth() + 1);

	str = str.replace(/w|W/g, Week[this.getDay()]);

	str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate());
	str = str.replace(/d|D/g, this.getDate());

	str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours());
	str = str.replace(/h|H/g, this.getHours());
	str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes());
	str = str.replace(/m/g, this.getMinutes());

	str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds());
	str = str.replace(/s|S/g, this.getSeconds());

	return str;
}

function resetClientWidth() {
	var width = document.body.clientWidth
	if(width >= 1920) {
		$('html').css('font-size', width/10 + 'px')
	} else {
		$(document.body).css('overflow', 'auto')
		$('html').css('font-size', 192 + 'px')
	}
}

resetClientWidth()

function isMobilePhone(n) {
	var reg = /^1[34578]\d{9}$/
	return reg.test(n)
}

function isTelPhone(n) {
	var reg = /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/
	return reg.test(n)
}

function getDateFromNow(days) {
	if(!days) {
		return new Date().format("yyyy-MM-dd")
	}
	var now = new Date().getTime()
	var diff = 24 * 3600 * 1000 * days
	return new Date(now + diff).format("yyyy-MM-dd")
}

function GetRequest() {
	var url = location.search; //获取url中"?"符后的字串
	var theRequest = new Object();
	if(url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for(var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
		}
	}

	return theRequest;
}

//判断输入字符串是否为空或全是空格
function isNull(str) {
	if(str == null) return true;
	if(str == "") return true;
	var regu = "^[ ]+$";
	var re = new RegExp(regu);
	var bb = re.test(str);
	return re.test(str);
}

/** 
 * 获取本周、本季度、本月、上月的开端日期、停止日期 
 */
var now = new Date(); //当前日期 
var nowDayOfWeek = now.getDay(); //今天本周的第几天 
var nowDay = now.getDate(); //当前日 
var nowMonth = now.getMonth(); //当前月 
var nowYear = now.getYear(); //当前年 
nowYear += (nowYear < 2000) ? 1900 : 0; //
nowYear = nowYear-1;//由于2018年没数据，故查询2017年数据（测试）
var lastMonthDate = new Date(); //上月日期 
lastMonthDate.setDate(1);
lastMonthDate.setMonth(lastMonthDate.getMonth() - 1);
var lastYear = lastMonthDate.getYear();
var lastMonth = lastMonthDate.getMonth();
//格局化日期：yyyy-MM-dd 
function formatDate(date) {
	var myyear = date.getFullYear();
	var mymonth = date.getMonth() + 1;
	var myweekday = date.getDate();
	if(mymonth < 10) {
		mymonth = "0" + mymonth;
	}
	if(myweekday < 10) {
		myweekday = "0" + myweekday;
	}
	return(myyear + "-" + mymonth + "-" + myweekday);
}
//获得某月的天数 
function getMonthDays(myMonth) {
	var monthStartDate = new Date(nowYear, myMonth, 1);
	var monthEndDate = new Date(nowYear, myMonth + 1, 1);
	var days = (monthEndDate - monthStartDate) / (1000 * 60 * 60 * 24);
	return days;
}
//获得本季度的开端月份 
function getQuarterStartMonth() {
	var quarterStartMonth = 0;
	if(nowMonth < 3) {
		quarterStartMonth = 0;
	}
	if(2 < nowMonth && nowMonth < 6) {
		quarterStartMonth = 3;
	}
	if(5 < nowMonth && nowMonth < 9) {
		quarterStartMonth = 6;
	}
	if(nowMonth > 8) {
		quarterStartMonth = 9;
	}
	return quarterStartMonth;
}

//获得本周的开端日期 
function getWeekStartDate() {
	var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
	return formatDate(weekStartDate);
}

//获得本周的停止日期 
function getWeekEndDate() {
	var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));
	return formatDate(weekEndDate);
}

//获得本月的开端日期 
function getMonthStartDate() {
	var monthStartDate = new Date(nowYear, nowMonth, 1);
	return formatDate(monthStartDate);
}

//获得本月的停止日期 
function getMonthEndDate() {
	var monthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth));
	return formatDate(monthEndDate);
}

//获得上月开端时候 
function getLastMonthStartDate() {
	var lastMonthStartDate = new Date(nowYear, lastMonth, 1);
	return formatDate(lastMonthStartDate);
}

//获得上月停止时候 
function getLastMonthEndDate() {
	var lastMonthEndDate = new Date(nowYear, lastMonth, getMonthDays(lastMonth));
	return formatDate(lastMonthEndDate);
}

//获得本季度的开端日期 
function getQuarterStartDate() {

	var quarterStartDate = new Date(nowYear, getQuarterStartMonth(), 1);
	return formatDate(quarterStartDate);
}

//或的本季度的停止日期 
function getQuarterEndDate() {
	var quarterEndMonth = getQuarterStartMonth() + 2;
	var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));
	return formatDate(quarterStartDate);
}
//获得本年的开始日期
function getYearStartDate() {
    //本年第一天
    var currentYearFirstDate=new Date(nowYear,0,1);
    return formatDate(currentYearFirstDate);
}

//获得本年的结束日期
function getYearEndDate() {
    //本年最后
    var currentYearLastDate=new Date(nowYear,11,31);
    return formatDate(currentYearLastDate);
}

//获得昨天日期
function getYearEndDate() {
    return getYesterday(-1, '-');
}

//近半年开始时间
function getHalfYearStartDate(){
	var date = new Date();
	date.setMonth(date.getMonth() - 6);
	var year = nowYear;
	var month = date.getMonth() + 1;
	month = (month < 10 ? "0" + month : month);
	return year.toString() + '-' + month.toString() + "-01";
}

//近半年结束时间
function getHalfYearEndDate(){
	var date = new Date();
	var currentMonth = date.getMonth();
	var nextMonth = ++currentMonth;
	var nextMonthFirstDay = new Date(nowYear, nextMonth-1, 1);
	var oneDay = 1000 * 60 * 60 * 24;
	return(new Date(nextMonthFirstDay - oneDay)).format("yyyy-MM-dd");
}

//获取过去12个月时间
function getLastYearMonthArray(){
	var dataArr = [],day,month;
    var data=new Date();
    var year=data.getFullYear()-1;
    data.setMonth(data.getMonth()+1)//获取到当前月份,设置月份
    for (var i = 0; i < 12; i++) {
    	data.setMonth(data.getMonth()-1);//每次循环一次 月份值减1
    	month = (data.getMonth()+1)<10?"0"+(data.getMonth()+1):data.getMonth()+1;
    	if(i==11){//过去第12个月
    		dataArr.push(data.getFullYear()+"-"+month+"-01")
    	}else if(i==0){//本月
    		var day = getDaysInMonth(data.getFullYear(),data.getMonth()+1);
    		dataArr.push(data.getFullYear()+"-"+month+"-"+day)
    	}else{
    		dataArr.push(data.getFullYear()+"-"+month)
    	}
    }
    return dataArr;
}

//根据年月实现获得当月天数
function getDaysInMonth(year,month){
	month = parseInt(month,10);  //parseInt(number,type)这个函数后面如果不跟第2个参数来表示进制的话，默认是10进制。
	var temp = new Date(year,month,0);
	return temp.getDate();
}

//获取昨天日期
function getYesterday(num, str){
	var today = new Date();
    var nowTime = today.getTime();
    var ms = 24*3600*1000*num;
    today.setTime(parseInt(nowTime + ms));
    var oYear = nowYear;
    var oMoth = (today.getMonth() + 1).toString();
    if (oMoth.length <= 1) oMoth = '0' + oMoth;
    var oDay = today.getDate().toString();
    if (oDay.length <= 1) oDay = '0' + oDay;
    return oYear + str + oMoth + str + oDay;
}

//获取过去6个月的开始时间
function getLastHalfMonthArray(dateStr){//格式：2018-07
	var dataArr = [],day,month,halfDate;
    var data=new Date();
    data.setFullYear(parseInt(dateStr.substring(0,4)));
    data.setMonth(parseInt(dateStr.substring(5,7)))//获取到当前月份,设置月份
    data.setMonth(data.getMonth()-6);//往前推半年，月份值减6
    month = (data.getMonth()+1)<10?"0"+(data.getMonth()+1):data.getMonth()+1;
    halfDate = data.getFullYear()+"-"+month+"-01"
    return halfDate;
}
