Chrome doesn’t recognize 24:00:00, while Firefox does

The following code outputs the NaN outputs in Chrome, and Firefox generates 1247547600000 .

 var str = "2009/07/13 24:00:00-0500"; document.write(Date.parse(str)); 

See the script .

How to solve this? Thanks!

EDIT: I have data from another company. I cannot change the received data. So what are the suggestions here?

Generated data:

 {"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"]} 
+4
source share
3 answers

You are asking the browser to analyze the invalid time. 24:00 is not valid. You probably mean 0:00 the next day. Chrome rejects it. Firefox is just more forgiving.

Please note that 24 hours a day. If the first hour is 00, the last hour is 23.

+5
source

It was just this problem that investigated it.

According to Wikipedia: (see http://en.wikipedia.org/wiki/ISO_8601 )

Midnight is a special case and can be called either β€œ00:00” or β€œ24:00”. The designation "00:00" is used at the beginning of the calendar day and is more often used. At the end of the day, use "24:00." Please note that "2007-04-05T24: 00" is the same as "2007-04-06TT00: 00", (see Combined date and time representations below).

So, it seems that Chrome is wrong.

+6
source

Chrome is right, 24:00 does not exist. The day ends at 23:59:59, and then the next day starts at 00:00:00. Your code should not generate dates from 24:00:00, because you have no guarantee of how it is interpreted by the browser or even if it works, now and in the future.

+1
source

All Articles