var myDate = new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth()+1;
if (month<10){
month = "0"+month;
}
var firstDay = year+"-"+month+"-01";
var myDate = new Date(year,month,0);
var lastDay = year+"-"+month+"-"+myDate.getDate();
//然后复制即可
datefeildStart.setValue(firstDay);
datefeildEnd.setValue(lastDay);
日期控件:
new Ext.form.DateField( {
fieldLabel : '开始日期',
id : 'beginDate',
width : 90,
//value:sys.sysDate.substring(0,7)+'-01',
value: timeYesterday,
format:'Y-m-d',
allowBlank : true,
listeners : {
specialkey : function(field, e){
if(e.getKey() == Ext.EventObject.ENTER){
loadGrid(settlementRrunStatusQueryDetailDatastore);
}
}
}
})
timeYesterday:
var curDate = new Date();
var preDate = new Date(curDate.getTime() - 24*60*60*1000);
var myDate = new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth()+1;
if (month<10){
month = "0"+month;
}
var firstDay = year+"-"+month+"-01";
var myDate = new Date(year,month,0);
var lastDay = year+"-"+month+"-"+myDate.getDate();
//
datefeildStart.setValue(firstDay);
datefeildEnd.setValue(lastDay);
//获取当前日期的前一天
var timeYesterday = preDate.format("Y") +"-" +preDate.format("m") + "-"+(preDate.format("d"));//昨天
//获取当前日期
var timeToday = curDate.format("Y") +"-" +curDate.format("m") + "-"+(curDate.format("d"));//今天
//获取本月的第一天
var timeFirstDay = preDate.format("Y") +"-" +preDate.format("m") + "-01";//本月第一天