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
Add a ment  | 

1 Answer 1

Reset to default 5

I'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.

本文标签: javascriptHow to convert ISO datetime to local datetime with momentjs Receiving odd outputStack Overflow