admin管理员组文章数量:1405363
I'm using moment.js to convert from an ISO date/time/zone string to a local one. Based on the docs and other similar questions such as this, what should be pretty straightforward is turning out not to be, and is giving me some odd output. Here is what I have:
console.log('date/time before is: ', date);
// date/time before is: 2016-12-23T23:10:00.000Z
var datetime = moment(date).format("dddd, MMMM Do YYYY, h:mm:ss a");
console.log('date/time after is: ', datetime);
// date/time after is: pátek, prosinec 23. 2016, 3:10:00 pm
The format string I am using is directly from the docs. The intent is to be able to format it in the way I need it once I get it working.
I'm using moment.js to convert from an ISO date/time/zone string to a local one. Based on the docs and other similar questions such as this, what should be pretty straightforward is turning out not to be, and is giving me some odd output. Here is what I have:
console.log('date/time before is: ', date);
// date/time before is: 2016-12-23T23:10:00.000Z
var datetime = moment(date).format("dddd, MMMM Do YYYY, h:mm:ss a");
console.log('date/time after is: ', datetime);
// date/time after is: pátek, prosinec 23. 2016, 3:10:00 pm
The format string I am using is directly from the docs. The intent is to be able to format it in the way I need it once I get it working.
Share Improve this question edited May 23, 2017 at 12:08 CommunityBot 11 silver badge asked Dec 24, 2016 at 1:38 skwnyskwny 3,1806 gold badges31 silver badges52 bronze badges 1- 1 its local date in czech locale. prosinec is December and pátek is Friday – s7vr Commented Dec 24, 2016 at 2:05
1 Answer
Reset to default 5I'm guessing that you are using moment-with-locales, because "pátek, prosinec" is Czech for "Friday, December".
I used the following cdn link for moment.js:
https://cdnjs.cloudflare./ajax/libs/moment.js/2.17.1/moment.min.js
And this code:
var date = new Date().toISOString();
console.log(date);
var datetime = moment(date).format("dddd, MMMM Do YYYY, h:mm:ss a");
console.log(datetime);
And got the expected result. Here's a fiddle using moment.js that produces the output I think you want.
版权声明:本文标题:javascript - How to convert ISO datetime to local datetime with moment.js? Receiving odd output - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744266352a2597967.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论