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!
Creating a moment object with a specific date and time is possible by calling the moment() function with arguments. Like the JavaScript Date, a moment object can be created from the number of milliseconds since 1970/1/1. Another possibility is using an array [year, month, day, hour, minute, second, milliseconds] .
However, Moment. js has too many drawbacks compared to modern date and time libraries. Its API is not immutable, it is large and it doesn't support tree shaking. Even the Moment team discourages to use their library in new projects.
The people behind Moment. js are even advising against using it. We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done.
MomentJs recently announced that the library is now deprecated. This is a big deal for the javascript community who actively downloads moment almost 15 million times a week. With that I began a journey during a Hackathon to replace moment in a core library at my company.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With