admin管理员组文章数量:1026989
Lost here. The following works in Chrome wonderfully, but in IE and FireFox "undefined undefined NaN Nan" is returned
What am I missing?
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 returns... Thursday, February 23 2012 etc, etc just perfectly.
Lost here. The following works in Chrome wonderfully, but in IE and FireFox "undefined undefined NaN Nan" is returned
What am I missing?
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 returns... Thursday, February 23 2012 etc, etc just perfectly.
Share Improve this question edited Mar 7, 2012 at 4:39 kinakuta 9,0371 gold badge40 silver badges48 bronze badges asked Mar 7, 2012 at 4:36 CeeMoneyCeeMoney 2153 silver badges10 bronze badges 4-
2
what is the value for the value ing out of
$(this).attr("ows_EventDate")
? – Alastair Pitts Commented Mar 7, 2012 at 4:43 -
This jsFiddle jsfiddle/jfriend00/rgMmH works fine for me in Chrome, Firefox and IE9. Since you haven't included the value of
$(this).attr("ows_EventDate");
, I had to bypass that. – jfriend00 Commented Mar 7, 2012 at 4:47 -
Also, do you realize that this is a very inefficient way to declare your arrays. You can just do this;
var day_names = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
– jfriend00 Commented Mar 7, 2012 at 4:49 - I realize that it's horribly inefficient now. Newb = me :) The value that ing in, for the February example above, would be "2012-02-04 21:00:00" – CeeMoney Commented Mar 7, 2012 at 4:54
2 Answers
Reset to default 6dateString must be formatted correctly. ISO 8601 date formats should work (http://www.iso/iso/date_and_time_format)
In your ment 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
.
Example: http://jsfiddle/TQjhP/
Your date "2012-02-04 21:00:00"
is not accepted by the Date()
constructor in IE.
See this related post for details: Javascript Date() constructor doesn't work.
The spec for what the Date()
constructor is supposed to accept as a string is RFC2822 if you really want the details of what is legal.
Apparently, Firefox and IE work with "2012/02/04 21:00:00"
.
See this article for further discussion.
Lost here. The following works in Chrome wonderfully, but in IE and FireFox "undefined undefined NaN Nan" is returned
What am I missing?
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 returns... Thursday, February 23 2012 etc, etc just perfectly.
Lost here. The following works in Chrome wonderfully, but in IE and FireFox "undefined undefined NaN Nan" is returned
What am I missing?
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 returns... Thursday, February 23 2012 etc, etc just perfectly.
Share Improve this question edited Mar 7, 2012 at 4:39 kinakuta 9,0371 gold badge40 silver badges48 bronze badges asked Mar 7, 2012 at 4:36 CeeMoneyCeeMoney 2153 silver badges10 bronze badges 4-
2
what is the value for the value ing out of
$(this).attr("ows_EventDate")
? – Alastair Pitts Commented Mar 7, 2012 at 4:43 -
This jsFiddle jsfiddle/jfriend00/rgMmH works fine for me in Chrome, Firefox and IE9. Since you haven't included the value of
$(this).attr("ows_EventDate");
, I had to bypass that. – jfriend00 Commented Mar 7, 2012 at 4:47 -
Also, do you realize that this is a very inefficient way to declare your arrays. You can just do this;
var day_names = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
– jfriend00 Commented Mar 7, 2012 at 4:49 - I realize that it's horribly inefficient now. Newb = me :) The value that ing in, for the February example above, would be "2012-02-04 21:00:00" – CeeMoney Commented Mar 7, 2012 at 4:54
2 Answers
Reset to default 6dateString must be formatted correctly. ISO 8601 date formats should work (http://www.iso/iso/date_and_time_format)
In your ment 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
.
Example: http://jsfiddle/TQjhP/
Your date "2012-02-04 21:00:00"
is not accepted by the Date()
constructor in IE.
See this related post for details: Javascript Date() constructor doesn't work.
The spec for what the Date()
constructor is supposed to accept as a string is RFC2822 if you really want the details of what is legal.
Apparently, Firefox and IE work with "2012/02/04 21:00:00"
.
See this article for further discussion.
本文标签: javascriptjquery date conversion chrome works but IE and firefox don39tStack Overflow
版权声明:本文标题:javascript - jquery date conversion chrome works but IE and firefox don't - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745556605a2155913.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论