Requirement: Two DateField controls: Start Time and end time. After the end time is selected, the month or number of days between the two time periods are automatically calculated. Problems to be Solved: 1. directly use Ext. getCmp (& amp; #39; endDate & amp; #39 ;). the date obtained by getValue () cannot be directly used... synta
Requirement: Two DateField controls: Start Time and end time. After the end time is selected, the month or number of days between the two time periods are automatically calculated.
Problems to be Solved:
1. The date obtained by directly using Ext. getCmp ('enddate'). getValue () cannot be used directly. You need to Format it using Ext. util. Format. date ().
2. The time difference calculated by default is millisecond, which requires conversion. 1 day = 86400000 milliseconds.
3. Use the Math. round () function to obtain the number.
4. Add a monitoring event to the date control of the end time.
[Javascript]
Var serviceTimeStart = new Ext. form. DateField ({
Name: "serviceTimeEnd", // The latest payment time parameter is the end time of the previous period
Id: "startdate ",
FieldLabel: "service start time ",
AllowBlank: false,
Width: 180,
TabIndex: 8,
Format: 'Y-m-d ',
BlankText: "cannot be blank"
});
Var serviceTimeEnd = new Ext. form. DateField ({
Name: "serviceTimeEnd ",
Id: "endDate ",
FieldLabel: "service termination time ",
Width: 180,
TabIndex: 9,
Format: 'Y-m-d ',
Listeners :{
Change: function ()
{
Var e = Ext. util. Format. date (Ext. getCmp ('enddate'). getValue (), 'Y-m-d'); // Format the date Control Value
Var s = Ext. util. Format. date (Ext. getCmp ('startdate'). getValue (), 'Y-m-d'); // Format the date Control Value
Var end = new Date (e );
Var start = new Date (s );
Var elapsed = Math. round (end. getTime ()-start. getTime ()/(86400000*30); // calculates the number of months at an interval.
Ext. MessageBox. alert (elapsed );
}
});