Reputation: 145
I am really new to JavaScript . I want to try moment.js but it doesn't work at all. I wrote the following simple code. More simple is not possible. Can you help me to find what I am missing ? Thank you in advance :)
console.log( moment().format()) ;
<!DOCTYPE html>
<html >
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/locale/da.js"></script>
</head>
<body>
<h1> test </h1>
</body>
</html>
Upvotes: 0
Views: 753
Reputation: 2517
You need to include the moment
library CDN itself (from here), not just the localization package you had included.
The problem could be easily found if you open your explorer dev tools and check for errors.
<!DOCTYPE html>
<html >
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/locale/da.js"></script>
</head>
<body>
<h1> test </h1>
<script>
console.log( moment().format()) ;
</script>
Upvotes: 2
Reputation: 353
You need to add the base momentjs library, the url is:
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script>
your code becomes
<!DOCTYPE html>
<html >
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script>
<script src="https://cdnjs.buttflare.com/ajax/libs/moment.js/2.22.2/locale/da.js"></script>*
</head>
<body>
<h1> test </h1>
<script>
console.log( moment().format()) ;
</script>
Upvotes: 2