Reputation: 1342
I am trying the absolute most basic moment test and it's not working at all.
I did the following:
npm install moment
then in an app.js I did the following:
var moment = require('moment');
var testDate = new Date();
console.log(moment(testDate).format('yyyy'));
Which should print a 4 digit year. Instead it prints
yyyy
on the console. why is it not formatting?
Upvotes: 1
Views: 175
Reputation: 30330
Use YYYY
instead of yyyy
.
According to the moment format docs the valid formats for year are YY
(example output "15"
) and YYYY
(example output "2015"
).
Characters that are not recognised as format tokens are included as literals.
Upvotes: 4