jqgrid根据时区显示不同的日期时间 [英] jqgrid is displaying different datetime based on time zones

查看:222
本文介绍了jqgrid根据时区显示不同的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jqgrid 4.1.2版本,并且服务器返回序列化为JSON的日期,如下所示"\/Date(1314443359000-0700)\/".

I'm using jqgrid 4.1.2 version and the server returns date serialized into JSON as below "\/Date(1314443359000-0700)\/".

问题是jqgrid没有显示服务器日期时间,但是当我更改本地时区时,它也会基于本地时区显示日期时间,因此显示的日期时间会有所不同.如何在jqgrid中显示服务器日期时间?

The problem is jqgrid is not displaying the server datetime but it displays datetime based on local time zone also when I change my local time zone the displayed datetime differs. How I can display the server datetime in jqgrid?

推荐答案

您描述的是正确行为.它与服务器中的同一时刻.如果我们两个人都希望同时在电话上通话,则必须将本地时间放在当地的日历中,以便可以同时讲话.

What you described is the correct behavior. It is the same time moment as in the server. If we both want talk on phone at the same time we have to place the local time in our outlook calender to be ready at the same moment to speak.

如果您需要日期转换的另一种实现方式,则可以使用自定义格式化程序.

If you need another implementation of the date conversion you can use custom formatter.

已更新:您可以定义myEditSerialize函数,并将其用作 serializeRowData .可以定义为以下

UPDATED: You can define you myEditSerialize function and use if as serializeEditData or as serializeRowData. Th can be defined as the following

var myEditSerialize = function (data) {
    var obj = $.extend({}, data);
    obj.RolloutTermin = jQuery.datepicker.parseDate('dd.mm.yy', data.RolloutDate);
    if (Date.isInstanceOfType(obj.RolloutDate)) {
        obj.RolloutDate= '\/Date(' + obj.RolloutDate.getTime() + ')\/';
    }
    return JSON.stringify(obj);
}

在示例中,我从"RolloutDate"列进行日期序列化,以便将其转换为服务器端的DateTime.如果直接使用Sys.Serialization.JavaScriptSerializer.serialize(data),则所有方法也都可以使用.我更喜欢使用 json2.js 中的JSON.stringify函数.

In the example I make date serialization from the column 'RolloutDate' so that it will be converted to the DateTime on the server side. If you would use Sys.Serialization.JavaScriptSerializer.serialize(data) directly all will works also. I prefer better to use JSON.stringify function from json2.js.

这篇关于jqgrid根据时区显示不同的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆