Webkit Boy Webkit Boy - 7 months ago 29
Javascript Question

How to use moment.js properly ?

I have made a sample page which contains this:

<!DOCTYPE HTML>
<html>
<head>
<style>
</style>
<script type="text/javascript" src="moment.js"></script>
</head>
<body>
<script>
var date = '2015-04-03';
var formate = 'LLLL';
var result = moment(date).format(format);
console.log(result);
</script>
</body>
</html>


And as you can see I have included the moment.js file in order to retrieve data from it and displaying a valid date in the browser. (Here is the link to moment.js that I have inlcuded: link)

But I don't know why it does not work at all! Can u guys help how to use moment.js in proper way ?! Thanks...

Answer

What about this one:

    <!DOCTYPE HTML>
<html>
<head>
<style>
</style>
<script src="https://cdn.jsdelivr.net/momentjs/2.13.0/moment.min.js"></script>
</head>
<body>
<script>
var date = '2015-04-03';
var result = 
moment(date).locale('fr').format('LLLL');
console.log(result);
</script>
</body>
</html>