迷失在这里。以下适用于Chrome,但在IE和FireFox中 返回“undefined undefined NaN Nan”
我错过了什么?
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日星期四等等,非常完美。
答案 0 :(得分:6)
dateString必须格式正确。 ISO 8601日期格式应该有效(http://www.iso.org/iso/date_and_time_format)
在评论中,您说dateString
等于2012-02-04 21:00:00
。用T
替换空格会使其成为所有浏览器都可以解析的有效日期格式,例如:
2012-02-04T21:00:00
。
答案 1 :(得分:1)
IE中的"2012-02-04 21:00:00"
构造函数不接受您的日期Date()
。
有关详细信息,请参阅此相关帖子:Javascript Date() constructor doesn't work。
Date()
构造函数作为字符串应该接受的内容的规范是RFC2822,如果你真的想要了解合法的细节。
显然,Firefox和IE使用"2012/02/04 21:00:00"
。
有关进一步的讨论,请参阅this article。