Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Moment.js以秒为单位动态更新时间_Javascript_Jquery_Momentjs - Fatal编程技术网

Javascript Moment.js以秒为单位动态更新时间

Javascript Moment.js以秒为单位动态更新时间,javascript,jquery,momentjs,Javascript,Jquery,Momentjs,我正在尝试使用矩.js来显示每秒更新的时钟(例如,1/5/2015 12:05:01然后1/5/2015 12:05:02,等等) 我找到了我的问题的以前的解决方案(请参阅),但是它不适用于最新版本的moment.js(v2.11.0)。提供的解决方案使用v2.6 有人能给我一些建议吗?这对我来说似乎很管用。对于相同的代码。只有moment.min.js指向v2.11.0 看一看代码(学分:给MilkyWayJoe)- 使用v2.11.0-您前面提到的解决方案目前确实有效。js v2.11.0

我正在尝试使用矩.js来显示每秒更新的时钟(例如,1/5/2015 12:05:01然后1/5/2015 12:05:02,等等)

我找到了我的问题的以前的解决方案(请参阅),但是它不适用于最新版本的moment.js(v2.11.0)。提供的解决方案使用v2.6


有人能给我一些建议吗?

这对我来说似乎很管用。对于相同的代码。只有moment.min.js指向v2.11.0

看一看代码(学分:给MilkyWayJoe)-


使用v2.11.0-

您前面提到的解决方案目前确实有效。js v2.11.0

代码:

但是,前面的解决方案中接受的答案中的JSFIDLE不起作用,并给出以下错误

"Refused to execute script from 'https://raw.github.com/timrwood/moment/1.6.2/moment.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled."
只需从适当的CDN加载脚本即可修复此问题,如下所示:

https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.0/moment.min.js

工作紧凑的解决方案

HTML


我错误地加载了javascript文件。谢谢你的快速回答。我犯了个愚蠢的错误。啊!我总是犯愚蠢的错误。快乐编码!:)
"Refused to execute script from 'https://raw.github.com/timrwood/moment/1.6.2/moment.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled."
https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.0/moment.min.js
<div id="datetime"></div>
var update = function() {
    document.getElementById("datetime")
    .innerHTML = moment().format('MMMM Do YYYY, h:mm:ss a');
}
setInterval(update, 1000);