01.var serviceTimeStart = new Ext.form.DateField({
02.name: "serviceTimeEnd",//最新交费时间参数为上期终止时间
03.id:"startdate",
04.fieldLabel: "服务开始时间",
05.allowBlank: false,
06.width: 180,
07.tabIndex: 8,
08.format: 'Y-m-d',
09.blankText: "不能为空"
10.
11.});
12.var serviceTimeEnd = new Ext.form.DateField({
13.// name: "serviceTimeEnd",
14.id:"endDate",
15.fieldLabel: "服务终止时间",
16.width: 180,
17.tabIndex: 9,
18.format: 'Y-m-d',
19.
20.listeners:{
21.change:function()
22.{
23.
24.var e = Ext.util.Format.date(Ext.getCmp('endDate').getValue(), 'Y-m-d');//格式化日期控件值
25.var s= Ext.util.Format.date(Ext.getCmp('startdate').getValue(), 'Y-m-d');//格式化日期控件值
26.
27.var end = new Date(e);
28.var start = new Date(s);
29.var elapsed = Math.round((end.getTime() - start.getTime())/(86400000*30)); // 计算间隔月数
30.
31.Ext.MessageBox.alert(elapsed);
32.}
33.}
34.});
--------------------------new Date(str) IE游览器提示NaN-------------------------------------- 处理如下:
/*
* new Date(str)
* 兼容不同浏览器
*/
function NewDate(str) {
str = str.split('-');
var date = new Date();
date.setUTCFullYear(str[0], str[1] - 1, str[2]);
date.setUTCHours(0, 0, 0, 0);
return date;
}