问题描述
在这里丢失以下作品在Chrome中奇妙地出现,但在IE和FireFox中,
undefined undefined NaN Nan被退回
Lost here. The following works in Chrome wonderfully, but in IE and FireFox"undefined undefined NaN Nan" is returned
我缺少什么?
var dateString = $(this).attr("ows_EventDate");
var current_date = new Date(dateString);
var month_names = [];
month_names[month_names.length] = "January";
month_names[month_names.length] = "February";
month_names[month_names.length] = "March";
month_names[month_names.length] = "April";
month_names[month_names.length] = "May";
month_names[month_names.length] = "June";
month_names[month_names.length] = "July";
month_names[month_names.length] = "August";
month_names[month_names.length] = "September";
month_names[month_names.length] = "October";
month_names[month_names.length] = "November";
month_names[month_names.length] = "December";
var day_names = [];
day_names[day_names.length] = "Sunday";
day_names[day_names.length] = "Monday";
day_names[day_names.length] = "Tuesday";
day_names[day_names.length] = "Wednesday";
day_names[day_names.length] = "Thursday";
day_names[day_names.length] = "Friday";
day_names[day_names.length] = "Saturday";
var startU = (day_names[current_date.getDay()]) + (", ")
+ (month_names[current_date.getMonth()]) + (" ") + current_date.getDate()
+ (" ") + (" ") + current_date.getFullYear();
Chrome返回... 2012年2月23日,星期四等完美。 b $ b
Chrome returns... Thursday, February 23 2012 etc, etc just perfectly.
推荐答案
dateString格式必须正确。 ISO 8601日期格式应该工作(http://www.iso.org/iso/date_and_time_format)
dateString must be formatted correctly. ISO 8601 date formats should work (http://www.iso.org/iso/date_and_time_format)
在你的评论中你说 dateString
等于 2012-02-04 21:00:00
。使用 T
替换空格将使其成为所有浏览器可以解析的有效日期格式,例如:
In your comment you said dateString
is equal to 2012-02-04 21:00:00
. Replacing the space with a T
would make it a valid date format that all browsers can parse, for example:
2012-02-04T21:00:00
。
示例:
这篇关于jquery日期转换chrome工程,但IE和firefox不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!