Reputation: 3140
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.
Upvotes: 3
Views: 9638
Reputation: 2300
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.com/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.
Upvotes: 5