admin管理员组文章数量:1333442
I'm having trouble formatting a date correctly in Moment.js. I'm using the format function with format "LLL D, YYYY" so it should return something like "Sep 15, 2016".
Instead, it's returning a the date in a weird format like "September 15, 2016 12:00 AM 15, 2016".
Here is my code, with the debugging info below.
moment.locale(picker.options.language);
console.log('picker.options.language:');
console.log(picker.options.language);
formatted = moment(picker.date).format(picker.format);
console.log('picker.date:');
console.log(picker.date);
console.log('picker.format:');
console.log(picker.format);
console.log('formatted:');
console.log(formatted);
And the console output from the above code:
I'm having trouble formatting a date correctly in Moment.js. I'm using the format function with format "LLL D, YYYY" so it should return something like "Sep 15, 2016".
Instead, it's returning a the date in a weird format like "September 15, 2016 12:00 AM 15, 2016".
Here is my code, with the debugging info below.
moment.locale(picker.options.language);
console.log('picker.options.language:');
console.log(picker.options.language);
formatted = moment(picker.date).format(picker.format);
console.log('picker.date:');
console.log(picker.date);
console.log('picker.format:');
console.log(picker.format);
console.log('formatted:');
console.log(formatted);
And the console output from the above code:
Share Improve this question asked Sep 15, 2016 at 17:20 amacrobertamacrobert 3,1793 gold badges30 silver badges46 bronze badges2 Answers
Reset to default 5This should work...
formatted = moment(picker.date).format('MMM D, YYYY')
Ref: http://momentjs./docs/#/parsing/string-format/
From http://momentjs./docs/#/displaying/format/ we can see that "LLL" represents the format "Month name, day of month, year, time". It seems you want "Month day, year", which is "LL".
Try:
picker.format = 'LL';
formatted = moment(picker.date).format(picker.format);
console.log(formatted);
Outputs (with today's date):
September 15, 2016
本文标签: javascriptHow to format a date in MomentjsStack Overflow
版权声明:本文标题:javascript - How to format a date in Moment.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742354678a2459172.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论