Date.prototype.format = function(format)
{
	var o = {
		"M+" : this.getMonth()+1, //month
        "d+" : this.getDate(),    //day
        "h+" : this.getHours(),   //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
        "S" : this.getMilliseconds() //millisecond
    }
    if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
        (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)if(new RegExp("("+ k +")").test(format))
    format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] :
                            ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
}

function getlastDate(last)
{
	//获取系统时间
    var LSTR_ndate=new Date();
    var LSTR_Year=LSTR_ndate.getFullYear();
    var LSTR_Month=LSTR_ndate.getMonth();
    var LSTR_Date=LSTR_ndate.getDate();
    //处理
    var uom = new Date(LSTR_Year,LSTR_Month,LSTR_Date);
    uom.setDate(uom.getDate()-last);//取得系统时间的前一天,重点在这里,负数是前几天
    var LINT_MM=uom.getMonth();
    LINT_MM++;
    var LSTR_MM=LINT_MM > 10?LINT_MM:("0"+LINT_MM)
    var LINT_DD=uom.getDate();
    var LSTR_DD=LINT_DD > 10?LINT_DD:("0"+LINT_DD)
    //得到最终结果
    var uom = (uom.format('yyyy-MM-dd'));
    return uom;
}

function inputForDate(e,obj,dateObj){
	e.preventDefault;
    var ind = obj.index();
    switch (ind){
     	case 0://今天
     		var startDate = (Date.today().format('yyyy-MM-dd'));
            var endDate = (Date.today().format('yyyy-MM-dd'));
            var val = startDate+' to '+endDate;
            dateObj.val(val);
            break;
     	case 1://昨天
            var startDate = getlastDate(1);
            var endDate = getlastDate(1);
            var val = startDate+' to '+endDate;
            dateObj.val(val);
            break;
        case 2://前七天
            var startDate = getlastDate(7);
            var endDate = getlastDate(1);
            var val = startDate+' to '+endDate;
            dateObj.val(val);
            break;
        case 3://上周
            var startDate=(moment().add(-1,'week').startOf('week').format('YYYY-MM-DD'));
            var endDate=(moment().add(-1,'week').endOf('week').format('YYYY-MM-DD'));     
            var val = startDate+' to '+endDate;
            dateObj.val(val);
            break;
        case 4://本月
            var startDate=(moment().startOf('month').format('YYYY-MM-DD'));
            var endDate=(Date.today().format('yyyy-MM-dd'));                                                                                       
            var val = startDate+' to '+endDate;
            dateObj.val(val);
            break;
        case 5://上月
            var startDate=(moment().add(-1,'month').startOf('month').format('YYYY-MM-DD'));
            var endDate=(moment().add(-1,'month').endOf('month').format('YYYY-MM-DD'));                                                                                       
            var val = startDate+' to '+endDate;
            dateObj.val(val);
            break;
     }
}