【问题标题】:Extjs 4.1 datefield - Set first and last day of current weekExtjs 4.1 datefield - 设置本周的第一天和最后一天
【发布时间】:2013-10-15 07:43:59
【问题描述】:

我尝试在 http://jsfiddle.net/uXkNr/

中创建一个带有 2 个日期字段的表单面板

这是我的物品

items: [{
        xtype: 'datefield',
        labelWidth: 50,
        format: 'd/m/Y',
        fieldLabel: 'From',
        name: 'from_date',
        value: new Date()  // First day of current week
    }, {
        xtype: 'datefield',
        labelWidth: 50,
        fieldLabel: 'To',
        format: 'd/m/Y',
        name: 'to_date',
        value: new Date()  // Last day of current week
    }]

我尝试设置本周的第一天和最后一天。示例

today 是:15/10/2013 (d/m/Y)。那么From 的日期是:14/10/2013,To 的日期是:20/10/2013。

这可能吗?怎么做,谢谢。

【问题讨论】:

    标签: extjs extjs4.1


    【解决方案1】:

    未经测试:

    var now = new Date(),
        startDay = 1, // monday
        currDay = now.getDay(),
        start = now,
        eDate = Ext.Date,
        sub, end;
    
    eDate.clearTime(now);
    if (currDay !== startDay) {
        // Sunday
        if (currDay === 0) {
            sub = 6;
        } else {
            sub = currDay - startDay;
        }
        start = eDate.add(now, eDate.DAY, -sub);
    }
    end = eDate.add(start, eDate.DAY, 6);
    console.log(start, end);
    

    【讨论】:

      猜你喜欢
      • 2011-01-06
      • 1970-01-01
      • 2017-07-21
      • 2021-07-21
      • 2016-07-18
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多