admin管理员组文章数量:1279083
I really have no idea what I'm doing wrong here. I can't get Datejs to properly parse "12:00 pm" however, it seems to work fine on other dates. Below is a clip from the Firefox debugger:
I really have no idea what I'm doing wrong here. I can't get Datejs to properly parse "12:00 pm" however, it seems to work fine on other dates. Below is a clip from the Firefox debugger:
Share Improve this question asked Jun 22, 2011 at 18:34 Chris DutrowChris Dutrow 50.4k67 gold badges195 silver badges262 bronze badges 6- 1 Works fine for me in Chrome running in the console directly on the datejs website – Matt Commented Jun 22, 2011 at 18:36
- Yeah, that worked for me too, actually – Chris Dutrow Commented Jun 22, 2011 at 18:37
- Which version of DateJS were you using in the above? – Matt Commented Jun 22, 2011 at 18:38
- 1 should also point out that "12:00 am" was incorrectly parsed to 12:00 instead of 00:00. – Mike Ruhlin Commented Jun 22, 2011 at 18:41
- Silly aside: if you think about the literal meaning of "pm" there is no "12:00 pm" - though you can say "1200" in 24-hour format, or "noon"... – nnnnnn Commented Jun 23, 2011 at 0:20
2 Answers
Reset to default 16Download the latest version of Datejs from SVN not the version in the "download" section.
Try wrapping the code in an IIFE.
<!DOCTYPE html>
<html>
<body>
<input type=text id=d onkeyup="parsedate()">
</input>
<br>
<span id=output></span>
<script type="text/javascript" src="../../../static/js/date.js"></script>
<script>
( function() {
parsedate = function() {
var input = document.getElementById('d').value;
var output = document.getElementById('output');
var d = Date.parse(input);
if (d !== null) {
output.innerHTML = d.toString();
} else {
output.innerHTML = "------"
}
}
}());
</script>
</body>
</html>
The IIFE being
(function(){
//code
}());
What I'm curious about is why FireFox behaves this way. I know they added security updates a few years back that prevent you from overwriting Date.prototype functions, but why is an IIFE capable of accessing this scope?
本文标签: javascriptDatejsProblem with 1200 pmStack Overflow
版权声明:本文标题:javascript - Datejs - Problem with 12:00 pm - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741261322a2367678.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论