I am having difficulties including moment.js in my browser code. This is my first time using it and teaching myself to use a library, so any help is appreciated. I have a CDN for moment in my html page:
<!-- jQuery cdn -->
<script src="http://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<!-- moment.js cdn -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/af.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="script.js"></script>
<script type="text/javascript">
var momentTest = moment();
console.log(momentTest); // this is not logging
</script>
Also in my script.js file, I have tried calling it another way with format() like I saw in the docs:
var now = moment().format();
console.log(now); //this is not logging either
But I keep getting a console error - Uncaught ReferenceError: moment is not defined. Can anyone help with this? I saw this article already but it didn't help me (total beginner with moment): How to use Moment.js?
This line does not load moment.js, but loads the af
(Afrikaans) locale for moment.js.
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/af.js"></script>
To load moment.js, you'd want to load the moment.js
file instead:
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
Try this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script> <script src="script.js"></script> <script type="text/javascript"> var momentTest = moment(); console.log(momentTest); // this is not logging </script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.