HTML:
<div class="date-list-center">
<a href="javascript:;" value="0">今天</a><a href="javascript:;" value="1">昨天</a>
<a href="javascript:;" value="2">本月</a>
<a href="javascript:;" value="3">上月</a>
<a href="javascript:;" value="4">本年</a>
<a href="javascript:;" value="5">本周</a>
<a href="javascript:;" value="6">上周</a>
</div>
<div class="date_outbox">
<input class="easyui-datebox" data-options="editable:false,buttons:buttons" prompt="起始日期" style="width:93px;" name="start_date" id="finance_startTime"></input>
--
<input class="easyui-datebox" data-options="editable:false,buttons:buttons" prompt="结束日期" style="width:93px;" name="end_date" id="finance_EndTime"></input>
</div>
JS
$(function() {
$(document).click(function(e){
closewin_flg = false;
});
//查询
$("#btn_mainquery").click(function() {
var jsonData = $("#dms_query_mianform").serializeObject();
pmsLoadDatagridByParam(mainDgName, jsonData);
});
$('.date-list-center a').click(function(){
var Text = $(this).text();
var today = new Date();
var oneday = 1000 * 60 * 60 * 24;
var nowDate= new Date();
//当前日
var nowDay = nowDate.getDate();
//今天是本周的第几天
var nowDayOfWeek= nowDate.getDay();
//当前月
var nowMonth = nowDate.getMonth();
//当前年
var nowYear = nowDate.getFullYear();
//var nowHours = nowDate.getHours();
//var nowMinutes = nowDate.getMinutes();
//var nowSeconds = nowDate.getSeconds();
nowYear += (nowYear < 2000) ? 1900 : 0;
//上月日期
var lastMonthDate = new Date();
lastMonthDate.setDate(1);
console.log(lastMonthDate.setDate(1));
lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
console.log(lastMonthDate.setMonth(lastMonthDate.getMonth()-1));
var lastYear = lastMonthDate.getYear();
console.log(lastYear);
var lastMonth = lastMonthDate.getMonth();
console.log(lastMonth);
var format='yyyy-MM-dd hh:mm:ss';
var begindate;
//-----进入循环-------
switch(Text)
{
//今天
case '今天':
begindate=new Date();
break;
//昨天
case '昨天':
begindate=new Date(today - oneday);
today=new Date(today - oneday);
break;
//一周
case '本周':
begindate= new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
break;
//上周
case '上周':
begindate= new Date(nowYear, nowMonth, nowDay - nowDayOfWeek -7);
today= new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek - 7));
break;
//本月
case '本月':
begindate= new Date(nowYear, nowMonth, 1);
break;
//上月
case '上月':
begindate= new Date(nowYear, lastMonth+1, 1);
today= new Date(nowYear, lastMonth+1, getMonthDays(lastMonth+1));
break;
//本年
case '本年':
begindate= new Date(nowYear,0, 1);
break;
if(begindate){
begindate.setHours(0);
begindate.setMinutes(0);
begindate.setSeconds(0);
begindate.setMilliseconds(0);
}
if(today){
today.setHours(23);
today.setMinutes(59);
today.setSeconds(59);
today.setMilliseconds(59);
}
}
var finance_startTime=timeStamp2String(begindate);
var finance_EndTime=timeStamp2String(today);
$('#finance_startTime').datebox('setValue', finance_startTime);
$('#finance_EndTime').datebox('setValue', finance_EndTime);
alert(timeStamp2String(begindate)+"----"+timeStamp2String(today));
});
});
//---------格式化日期---------
function timeStamp2String(time){
var datetime = new Date();
datetime.setTime(time);
var year = datetime.getFullYear();
var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
}