“moment is not defined” using moment.js

2020-03-08 08:48发布

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

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");

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

any tips would be greatly appreciated!

1条回答
冷血范
2楼-- · 2020-03-08 09:25

With latest 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>

查看更多
登录 后发表回答