Javascript 使用moment.js“未定义时刻”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44609306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:38:58  来源:igfitidea点击:

"moment is not defined" using moment.js

javascripttimemomentjs

提问by alej_dra

I am working with moment.js, but as I am testing the moment.js library I continue to receive an error.

我正在使用 moment.js,但在测试 moment.js 库时,我继续收到错误消息。

var back30Days=moment().subtract(30, 'days').format("dddd, MMMM Do YYYY, h:mm:ss p");

it returns "moment not defined." referring to .format("dddd, MMMM Do YYYY, h:mm:ss p");

它返回“ moment not defined.”指的是.format("dddd, MMMM Do YYYY, h:mm:ss p");

I've read the documentation, and everything looks fine, but when I reload my page, the js I'm working with won't load.

我已经阅读了文档,一切看起来都很好,但是当我重新加载页面时,我正在使用的 js 不会加载。

any tips would be greatly appreciated!

任何提示将非常感谢!

回答by Dalin Huang

With latest momentjs:

使用最新的momentjs:

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>

var back30Days=moment().subtract(30, 'days').format("dddd, MMMM Do YYYY, h:mm:ss p");

console.log('back30Days --> ' + back30Days);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>