开发者

How to get date of one day before in extjs field

I have the following date field i want to get date of one day before , how can i get that ? In my form panel

 items: [{
    fieldLabel: 'Start Date',
    name: 'fromdate',
    ref: '../fromdate',
    id: 'fromdate',
    vtype: 'daterange',
    value: new Date(),
    endDateField: 'todate' // id of the end date field
}, {
    fieldLabel: 'End Date',
    name: 'todate',
    id: 'todate',
    vtype: 'daterange',
    value: new 开发者_StackOverflow社区Date(),
    startDateField: 'fromdate' // id of the start date field
}]

Today I am getting 03/23/2011 but I want 03/22/2011 How I can get 03/22/2011?


Speaking ExtJS language, you can use Ext.Date library for manipulation dates. For example:

        Ext.Date.add (new Date(),Ext.Date.DAY,1)

Depending on your code logic, you can modify the default value of date field by several ways:

1) In the item's value configuration:

        {
            ...
            vtype: 'daterange',
            value : Ext.Date.add (new Date(),Ext.Date.DAY,1),
            fromDateField: 'fromdate',
            ...
        }

2) During the component's event. Basically, ExtJS containers have initComponent method which is the most first running, but be sure to set your code after callParent() method in order to access items collection. Example:

initComponent: function() {
            ...
    this.callParent(arguments);
            this.items.getByKey('fromdate').value = Ext.Date.add (new Date(),Ext.Date.DAY,1);
            ...
}


Try this:

new Date().add(Date.DAY, -1);


Or this:

var date = new Date();
date.setDate(date.getDate()-1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜