免费jqGrid 4.9.0-MAC上Safari上的日期格式 [英] Free jqGrid 4.9.0 - Dates format on Safari on MAC

查看:74
本文介绍了免费jqGrid 4.9.0-MAC上Safari上的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows上运行时,在所有主要的4种浏览器(Safari,Chrome,IE和Firefox)上测试日期格式选项都很好.

Testing date format options on all major 4 browsers (Safari, Chrome, IE & Firefox) while working on windows works well.

但是,在MAC机器上进行测试时,格式选项在Safari中失败了(MAC上的Firefox运行良好).

However, when testing it on MAC machines, the format option failed within Safari (Firefox on MAC works well).

我的格式选项是:

gridField.formatter = 'date';
gridField.formatoptions = {};
gridField.formatoptions['srcformat'] = 'U/1000';
gridField.formatoptions['newformat'] = 'm/d/Y H:i:s';

在Safari中(仅在MAC上)将产生:NaN/NaN/NaN NaN:Nan:NaN.

Which in Safari (on a MAC only) will yield: NaN/NaN/NaN NaN:Nan:NaN.

有什么办法解决这个问题吗?

Any idea how to overcome the problem?

谢谢

推荐答案

问题如下.免费的jqGrid使用的$.jgrid.parseDate函数代码与jqGrid 4.7大致相同.它支持在两种不同情况中以日期格式使用"u""U".第一种情况是使用"u""U" 而没有任何格式说明(例如,srcformat:"u").这意味着jqGrid使用new Date(inputValue*1000)来解析输入值. 1418297439之类的输入值将使用newformat: "m/d/Y H:i:s"显示为12/11/2014 11:30:39.另一方面,您在输入数据中使用的是1418297439000而不是1418297439,并且jqGrid没有针对这种情况的确切格式设置.

The problem is the following. Free jqGrid uses mostly the same code of $.jgrid.parseDate function like jqGrid 4.7. It support the usage "u" and "U" in the date format in two different cases. The first case is the usage of "u" and "U" without any additional format specification (for example, srcformat:"u"). It means that jqGrid uses new Date(inputValue*1000) to parse the input value. The input value like 1418297439 will be displayed as 12/11/2014 11:30:39 using newformat: "m/d/Y H:i:s". On the other side you have 1418297439000 instead of 1418297439 in the input data and jqGrid don't have some exact formatter for the case.

您在原始演示 http://jsfiddle.net/OlegKi/ngm5rhgp/7/.这种格式("U/1000")根本不存在.格式"U/1000"的解释方式与"U/""U.""U/BlaBla""U:H:i:s"或其他以u开头并带有分隔符的方式相同.由于输入数据看起来像1418297439000并且没有其他分隔符(,/,等),因此只有第一个格式化程序U将使用,但现在将其解释为u格式化程序,表示毫秒. u格式通常用于12/11/2014 11:30:39,123之类的格式,其中最后一个123部分是时间的毫秒部分.

You use format srcformat: "U/1000" in your original demo http://jsfiddle.net/OlegKi/ngm5rhgp/7/. Such format ("U/1000") don't exist at all. The format "U/1000" will be interpretet in the same way like "U/", "U.", "U/BlaBla", "U:H:i:s" or any other which start with u following with separator. Because the input data looks like 1418297439000 and have no additional separators (,, /, , , and some other) then only the first formatter U will be used, but it will be interpreted now as u formatter, which means millisecond. The u format will be used typically for the format like 12/11/2014 11:30:39,123 where tha last 123 part is the millisecond part of the time.

MAC上的Safari似乎不允许将日期创建为new Date(1970, 1, 1, 0, 0, 1418297439000),该日期将jqGrid与1418297439000用作输入数据,将srcformat: "U/1000"用作日期.

It seems that Safari on MAC don't allow to create the date as new Date(1970, 1, 1, 0, 0, 1418297439000) which uses jqGrid with 1418297439000 as input data and srcformat: "U/1000".

我建议您修改输入数据和srcformat: "u"格式的用法.需要枚举输入数据的所有项,并将start_timeend_time属性指定为100.我在演示 http://jsfiddle.net/OlegKi/ngm5rhgp/8/中使用了代码

What I suggest you to do is modifying the input data and the usage of srcformat: "u" format. One need to enumerate all items of input data and to devide start_time and end_time properties to 100. I used in my demo http://jsfiddle.net/OlegKi/ngm5rhgp/8/ the code

var mydata = [{...},{...}... {...}], n = mydata.length, item, i;

for (i = 0; i < n; i++) {
    item = mydata[i];
    item.start_time = Math.floor(item.start_time / 1000);
    item.end_time = Math.floor(item.end_time / 1000);
}

,并将srcformat: "U/1000"替换为srcformat: "u".如果您没有"local"datatype,则可以在beforeProcessing回调内部修改数据.

and have replaces srcformat: "U/1000" to srcformat: "u". If you have not "local" value of datatype than you can modify the data inside of beforeProcessing callback.

已更新:为简化自Unix纪元(1970年1月1日00:00:00 GMT)以来的时间(以毫秒为单位),就像1418297439000一样,我在免费的jqGrid中引入了 new格式选项:srcformat: "u1000" .新的演示 http://jsfiddle.net/OlegKi/ngm5rhgp/9/ 使用未修改输入数据,而仅使用srcformat: "u1000"而不是srcformat: "U/1000".要使用它,必须使用来自 GitHub 的最新免费jqGrid.

UPDATED: To simplify processing of the time in milliseconds since the Unix Epoch (January 1 1970 00:00:00 GMT), like 1418297439000, I introduced in free jqGrid new format option: srcformat: "u1000". The new demo http://jsfiddle.net/OlegKi/ngm5rhgp/9/ uses unmodified input data and just use srcformat: "u1000" instead of srcformat: "U/1000". To use it one have to use the latest free jqGrid from GitHub.

这篇关于免费jqGrid 4.9.0-MAC上Safari上的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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