ext对于日期格式化后为什么排序不起作用了

{header : '生效时间',dataIndex : 'productStartTime',width:80,renderer : ExtJSUtils.dateRender},
{header : '失效时间',dataIndex : 'productEndTime',width:80,renderer : ExtJSUtils.dateRender}

这是自定义的renderer函数
dateRender : function(value, meta, record, rowIndex, colIndex, store) {
var returnValue = "";
if (value == "" || value == null || value == 0) {
return returnValue;
}
if (typeof value == "object") {
            //var str=Ext.encode(value);

            returnValue = Ext.util.Format.date(new Date(value.time), 'Y年m月d日');
        } else {
            returnValue = value.substr(0, 19);
        }
        return returnValue;
    }


微软在做json序列化的时候把datetime类型搞成了一个比较怪异的形式"\/Date(10000000000-0700)\/" ,为什么要这样做我也没仔细看,可以参考 AJAX JSON中日期类型DateTime格式化的序列化自定义对象以及自定义类型参数的问题处理 文章写的比较详细.

按照文章给的方法,在反序列化前先用正则表达式替换一下.不过我发现不起作用.既然客户端不起作用我就转到服务器端来处理,方法类似,都是正则表达式处理

string sPattern = @"\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}"; //日期的正则

可依然不行,仔细分析了一下发现是extjs返回的日期比较奇怪
"[{\"BudgetDate\":\"2009-07-07T00:00:00\"}]"
注意到了吗?中间有个T 不明白为什么会有个T呢?

我用的方法是extjs 自带的序列化方法 Ext.util.JSON.encode(_temp)

转换之前的日期数据为: Tue Jul 7 00:00:00 UTC+0800 2009

怎么转换完就多了一个T呢?

最后把这个T替换掉就ok啦.

顺带记录一下 extjs判断Date格式的方法

obj.constructor==Date 就行了

如果是function就是 foo.prototype.constructor
如果是object就是 obj.constructor

你这个和我的问题无关> 微软在做json序列化的时候把datetime类型搞成了一个比较怪异的形式"\/Date(10000000000-0700)\/" ,为什么要这样做我也没仔细看,可以参考 AJAX JSON中日期类型DateTime格式化的序列化自定义对象以及自定义类型参数的问题处理 文章写的比较详细.

按照文章给的方法,在反序列化前先用正则表达式替换一下.不过我发现不起作用.既然客户端不起作用我就转到服务器端来处理,方法类似,都是正则表达式处理

string sPattern = @"\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}"; //日期的正则

可依然不行,仔细分析了一下发现是extjs返回的日期比较奇怪
"[{\"BudgetDate\":\"2009-07-07T00:00:00\"}]"
注意到了吗?中间有个T 不明白为什么会有个T呢?

我用的方法是extjs 自带的序列化方法 Ext.util.JSON.encode(_temp)

转换之前的日期数据为: Tue Jul 7 00:00:00 UTC+0800 2009

怎么转换完就多了一个T呢?

最后把这个T替换掉就ok啦.

顺带记录一下 extjs判断Date格式的方法

obj.constructor==Date 就行了

如果是function就是 foo.prototype.constructor
如果是object就是 obj.constructor

这种写法,最后日期变成了字符串。
试下这个
renderer:function(value){

if(value instanceof Date){

return new Date(value).format("Y-m-d");

}else{

return value;

}

}

http://blog.csdn.net/mingxunzh/article/details/4745534