Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在ExtJS中获取开始/结束日期之间的日期_Javascript_Date_Extjs - Fatal编程技术网

Javascript 在ExtJS中获取开始/结束日期之间的日期

Javascript 在ExtJS中获取开始/结束日期之间的日期,javascript,date,extjs,Javascript,Date,Extjs,我想知道两次约会之间的距离。这是我使用的代码: var startDateStr = Ext.getCmp('startDateFoi').getSubmitValue(); //console.log(startDateStr); // 10-Mar-2015 var endDateStr = Ext.getCmp('endDateFoi').getSubmitValue(); //console.log(en

我想知道两次约会之间的距离。这是我使用的代码:

          var startDateStr = Ext.getCmp('startDateFoi').getSubmitValue();
           //console.log(startDateStr); // 10-Mar-2015
          var endDateStr = Ext.getCmp('endDateFoi').getSubmitValue();
           //console.log(endDateStr); // 12-Mar-2015

            allDates = [];

            while (startDateStr <= endDateStr) {
                allDates.push(new Date(startDateStr));
                startDateStr.setDate(startDateStr.getDate() + 1);
            }

            console.log(allDates);
var startDateStr=Ext.getCmp('startDateFoi').getSubmitValue();
//console.log(startDateStr);//2015年3月10日
var endDateStr=Ext.getCmp('endDateFoi').getSubmitValue();
//console.log(endDateStr);//2015年3月12日
所有日期=[];

while(startDateStr您可以使用Ext.Date类来处理此问题:

或者,如果您想要标准JS版本,以便了解其工作原理:


毕竟我是这样做的: 首先我做了一个函数:

         var ImagedbyDate = function(){ 
           $(document).ready(function(){

        // GET ALL THE DATES BETWEEN TWO SELECTED DAYS AND STORE THEM IN AN ARRAY (allDates[])

             var startDateStr = Ext.getCmp('startDateFoi').getSubmitValue();
             alert(startDateStr);
             var endDateStr = Ext.getCmp('endDateFoi').getSubmitValue();
             alert(endDateStr);

             currentDate = new Date(startDateStr);
             endDate = new Date(endDateStr);
             alert(currentDate);
             allDates = [];

            while (currentDate <= endDate) {
                allDates.push(new Date(currentDate));
                currentDate.setDate(currentDate.getDate() + 1);
            }
以下是我的物品的外观:

    {
            region: 'center', 
            title: "Rural Broadband",
            layout: 'fit',
            collapsible: false,
            items: [mappanel] , //mapPanel
            dockedItems: [{ //Toolbar with Actions - Beginn
                xtype: 'toolbar',
                dock: 'top',
                items: [{
                text: 'Current center of the map',
                handler: function(){
                    var c = GeoExt.panel.Map.guess().map.getCenter();
                    Ext.Msg.alert(this.getText(), c.toString());
                    }
                },{
                text: 'See Unassigned Images',
                handler: function(){
                    UnassignedImg();
                    }   
                },
                {
                    fieldLabel: 'Start Date',
                    name: 'startDate',
                    xtype: 'datefield',
                    id: 'startDateFoi',
                    format: 'd-M-Y'
                },
                {
                    fieldLabel: 'End Date',
                    name: 'startDate',
                    id: 'endDateFoi',
                    xtype: 'datefield',
                    format: 'd-M-Y'
                }, ...

我希望这对某人有所帮助。

这是一个冗长而过于复杂的问题,请参阅我的答案,了解单线解决方案,而不是循环解决方案
         var ImagedbyDate = function(){ 
           $(document).ready(function(){

        // GET ALL THE DATES BETWEEN TWO SELECTED DAYS AND STORE THEM IN AN ARRAY (allDates[])

             var startDateStr = Ext.getCmp('startDateFoi').getSubmitValue();
             alert(startDateStr);
             var endDateStr = Ext.getCmp('endDateFoi').getSubmitValue();
             alert(endDateStr);

             currentDate = new Date(startDateStr);
             endDate = new Date(endDateStr);
             alert(currentDate);
             allDates = [];

            while (currentDate <= endDate) {
                allDates.push(new Date(currentDate));
                currentDate.setDate(currentDate.getDate() + 1);
            }
        currentDate = new Date(startDateStr);
        endDate = new Date(endDateStr);
    {
            region: 'center', 
            title: "Rural Broadband",
            layout: 'fit',
            collapsible: false,
            items: [mappanel] , //mapPanel
            dockedItems: [{ //Toolbar with Actions - Beginn
                xtype: 'toolbar',
                dock: 'top',
                items: [{
                text: 'Current center of the map',
                handler: function(){
                    var c = GeoExt.panel.Map.guess().map.getCenter();
                    Ext.Msg.alert(this.getText(), c.toString());
                    }
                },{
                text: 'See Unassigned Images',
                handler: function(){
                    UnassignedImg();
                    }   
                },
                {
                    fieldLabel: 'Start Date',
                    name: 'startDate',
                    xtype: 'datefield',
                    id: 'startDateFoi',
                    format: 'd-M-Y'
                },
                {
                    fieldLabel: 'End Date',
                    name: 'startDate',
                    id: 'endDateFoi',
                    xtype: 'datefield',
                    format: 'd-M-Y'
                }, ...