Javascript Date.parse帮助 [英] Javascript Date.parse help
问题描述
我正在使用Javascript Date.parse()
来检查结束时间后的开始时间。
有时候是这样的:
Date.parse(12:00 pm)> Date.parse(9:30 pm)
在Chrome中,这是假的(因为它应该)
在IE中,它不正确地出现为true。
Chrome查看的值为: p>
2010年7月22日12:00:00 GMT-0400(东部夏令时)
2010年7月22日21:30 :00 GMT-0400(Eastern Daylight Time)
IE看到的值是:
7月22日12:00:00 EDT 2010
7月22日09:30:00 EDT 2010
如何使IE正常工作?
update
确定这只是在IE7中发生。另外我现在看到IE7没有得到存储在SELECT框中的am / pm,并通过以下方式获取:
var startMerid = document.getElementById(start_time_ampm)。options [document.getElementById(start_time_ampm)。selectedIndex] .value;
我的选择是这样的:
< option> am< / option>
但我更改为:
< option value =am> am< / option>
现在可以使用。
IE中的 Date.parse()
的文档显示如下:
如果使用24小时制,在中午12点之前指定PM是一个错误。例如,23:15 PM是一个错误。
对于跨浏览器解决方案,您应该避免解析()并手动解析时间字符串。或者,您可以使用跨浏览器库来解析日期/时间 - DateJS 是受欢迎的。 / p>
I am using Javascript Date.parse()
to check if a start time is after an end time.
The time in question is like this:
Date.parse("12:00pm") > Date.parse("9:30pm")
In Chrome this is coming up as false (as it should)
In IE it is incorrectly coming up as true.
The values Chrome see's are:
Thu Jul 22 2010 12:00:00 GMT-0400 (Eastern Daylight Time)
Thu Jul 22 2010 21:30:00 GMT-0400 (Eastern Daylight Time)
The values IE sees are:
Thu Jul 22 12:00:00 EDT 2010
Thu Jul 22 09:30:00 EDT 2010
How can I make IE work correctly?
update
OK this is only happening in IE7. Also I see now IE7 is not getting the am/pm which is stored in a SELECT box and retrieved via:
var startMerid = document.getElementById("start_time_ampm").options[document.getElementById("start_time_ampm").selectedIndex].value;
My select was like this:
<option>am</option>
but I changed to:
<option value="am">am</option>
and it now works.
The docs for Date.parse()
in IE state the following:
If the 24-hour clock is used, it is an error to specify "PM" for times later than 12 noon. For example, "23:15 PM" is an error.
For a cross-browser solution, you should avoid parse() and parse the time string manually. Alternatively, you could use a cross-browser library for parsing dates/times - DateJS is a popular one.
这篇关于Javascript Date.parse帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!