最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get ExtJS to include timezone when saving record from JsonStore wISO 8601 format? - Stack Overflow

programmeradmin1浏览0评论

In the snippet below, I am creating a JsonStore (whose record type is a single date field), adding a new record to it, then saving it. When saving, the time zone is not included in the serialized date value, even though it is included with the actual record object (as shown by Firebug). Ext seems to convert the date into the browser's timezone, but then drop the time zone, when sending the request to the server. I am using the ISO 8601 datetime format ('c'), which if I am reading the Ext docs correctly, should include the time zone.

Even if it is converting to the browser's time zone, that wouldn't be a problem for me as long as it includes that time zone when saving the record. As it stands now, the server must be written such that it parses ining dates in the browser's time zone, but sends them to the client in a possibly different time zone, which seems kludgy. Any suggestions? I read through several seemingly related questions on the Ext forums but they seemed to be dealing with slightly different issues.

var myDataStore = new Ext.data.JsonStore({
    url: '/api/echo',    
    writer: new Ext.data.JsonWriter({
        encode: false,
        writeAllFields: true
    }),
    root: 'records',
    fields: [
        {name: 'myDate', type: 'date', dateFormat: 'c'}
    ],
    autoSave: false,
    autoLoad: false
});

myDataStore.add(new myDataStore.recordType({myDate: Date.parseDate('2010-11-08T11:00:00.000-0000','c')}));
myDataStore.save();

Serialized data (no time zone):

{"records":{"myDate":"2010-11-08T06:00:00"}}

In the snippet below, I am creating a JsonStore (whose record type is a single date field), adding a new record to it, then saving it. When saving, the time zone is not included in the serialized date value, even though it is included with the actual record object (as shown by Firebug). Ext seems to convert the date into the browser's timezone, but then drop the time zone, when sending the request to the server. I am using the ISO 8601 datetime format ('c'), which if I am reading the Ext docs correctly, should include the time zone.

Even if it is converting to the browser's time zone, that wouldn't be a problem for me as long as it includes that time zone when saving the record. As it stands now, the server must be written such that it parses ining dates in the browser's time zone, but sends them to the client in a possibly different time zone, which seems kludgy. Any suggestions? I read through several seemingly related questions on the Ext forums but they seemed to be dealing with slightly different issues.

var myDataStore = new Ext.data.JsonStore({
    url: '/api/echo',    
    writer: new Ext.data.JsonWriter({
        encode: false,
        writeAllFields: true
    }),
    root: 'records',
    fields: [
        {name: 'myDate', type: 'date', dateFormat: 'c'}
    ],
    autoSave: false,
    autoLoad: false
});

myDataStore.add(new myDataStore.recordType({myDate: Date.parseDate('2010-11-08T11:00:00.000-0000','c')}));
myDataStore.save();

Serialized data (no time zone):

{"records":{"myDate":"2010-11-08T06:00:00"}}
Share Improve this question asked Nov 8, 2010 at 14:40 Jeff EvansJeff Evans 1,3071 gold badge16 silver badges32 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Updating the answer for Ext-JS 4:

Ext.JSON.encodeDate = function(o)
{
   return '"' + Ext.Date.format(o, 'c') + '"';
};

Nevermind, apparently the magic Google phrase was "extjs time zone serialize". This seems to be a known issue. The solution seems fairly simple:

Ext.util.JSON.encodeDate = function(o)
{
   return '"' + o.format('c') + '"';
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论