Convert 'Jul' to 'July' with moment.js

Viewed 65

I have this response Wed Jul 20 2022 00:00:00 GMT+0300 (Ora de vară a Europei de Est) and I need to convert Jul to July. Is any chance to do it with moment.js? If not, maybe simple way to convert it with vanilla JS.

3 Answers

This

moment(new Date("Wed Jul 20 2022 00:00:00 GMT+0300")).format('MMMM');

will return 'July';

You can find more there : https://momentjs.com/

JS Date objects now natively support locale methods for this sort of thing, which has the benefit of working for the whole world (which most regex-based or string-substitution based strategies for this type of problem will not):

let d = new Date("Wed Jul 20 2022 00:00:00 GMT+0300")

console.log(d.toLocaleString('default', { month: 'long' }))

You can get this using the format method of moment

  • Using MMMM you can get July

Check this out click here

moment().format('MMMM Do YYYY, h:mm:ss a');
Related