admin管理员组文章数量:1396858
The following code outputs outputs NaN
in Chrome while Firefox generates 1247547600000
.
var str = "2009/07/13 24:00:00-0500";
document.write(Date.parse(str));
See this fiddle.
How to solve this? Thank you!
EDIT: I've got the data from another pany. I cannot change the data it generates. So What are the suggestions here?
The data generated:
{"day":"2009-07-13", "work":["11:16:35-12:03:12", "12:32:48-13:26:28", "13:39:09-13:39:12", "13:41:03-13:41:05", "14:18:09-24:00:00"]},
{"day":"2009-07-14", "work":["00:00:00-07:22:25", "07:22:25-07:22:28", "10:10:04-10:10:31", "10:10:32-10:15:33", "10:18:07-10:21:19", "11:04:49-11:06:15", "11:12:50-11:19:05", "11:19:11-11:19:19", "11:45:50-11:51:42", "11:51:43-11:53:55", "14:03:13-14:13:04", "14:23:55-14:31:28", "14:31:28-14:38:00", "14:38:00-14:49:04", "16:34:56-16:44:33", "16:46:37-16:48:10", "16:48:11-24:00:00"]}
The following code outputs outputs NaN
in Chrome while Firefox generates 1247547600000
.
var str = "2009/07/13 24:00:00-0500";
document.write(Date.parse(str));
See this fiddle.
How to solve this? Thank you!
EDIT: I've got the data from another pany. I cannot change the data it generates. So What are the suggestions here?
The data generated:
{"day":"2009-07-13", "work":["11:16:35-12:03:12", "12:32:48-13:26:28", "13:39:09-13:39:12", "13:41:03-13:41:05", "14:18:09-24:00:00"]},
{"day":"2009-07-14", "work":["00:00:00-07:22:25", "07:22:25-07:22:28", "10:10:04-10:10:31", "10:10:32-10:15:33", "10:18:07-10:21:19", "11:04:49-11:06:15", "11:12:50-11:19:05", "11:19:11-11:19:19", "11:45:50-11:51:42", "11:51:43-11:53:55", "14:03:13-14:13:04", "14:23:55-14:31:28", "14:31:28-14:38:00", "14:38:00-14:49:04", "16:34:56-16:44:33", "16:46:37-16:48:10", "16:48:11-24:00:00"]}
Share
Improve this question
edited Jul 19, 2012 at 15:47
sozhen
asked Jul 19, 2012 at 15:13
sozhensozhen
7,67714 gold badges38 silver badges53 bronze badges
3
- 2 Post the code here, not just in the fiddle. – epascarello Commented Jul 19, 2012 at 15:14
- 9 well, technically there is no 24:00 - it's 0:00 of the next day. – Christoph Commented Jul 19, 2012 at 15:15
- possible duplicate of Ecmascript 5 Date.parse for ISO 8601 test cases – epascarello Commented Jul 19, 2012 at 15:18
3 Answers
Reset to default 7Just had this problem and researched it.
According to Wikipedia: (see http://en.wikipedia/wiki/ISO_8601 )
Midnight is a special case and can be referred to as both "00:00" and "24:00". The notation "00:00" is used at the beginning of a calendar day and is the more frequently used. At the end of a day use "24:00". Note that "2007-04-05T24:00" is the same instant as "2007-04-06T00:00" (see Combined date and time representations below).
So it seems Chrome is wrong.
You are asking the browser to parse an invalid time. 24:00 isn't valid. You probably mean 0:00 of the next day. Chrome is correct in rejecting it. Firefox is simply more forgiving.
Consider that there are 24 hours in the day. If the first hour is 00, then the last hour is 23.
Chrome is right, 24:00 doesn't exists. The day ends at 23:59:59, and then the next day starts on 00:00:00. Your code should not generate dates with 24:00:00, 'cause you have no guarantee of how it is interpreted by the browser or even if it works, now and in the future.
本文标签: javascriptChrome not recognizing 240000 while Firefox doesStack Overflow
版权声明:本文标题:javascript - Chrome not recognizing 24:00:00 while Firefox does - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744142767a2592693.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论