我尝试在 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
}]
我尝试设置本周的第一天和最后一天。示例
今天
是:2013 年 10 月 15 日(日/月/年)。那么 From
的日期为:14/10/2013,To
的日期为:20/10/2013。
这可能吗?怎么做谢谢。
最佳答案
未经测试:
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);
关于Extjs 4.1 datefield - 设置本周的第一天和最后一天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19375771/