Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get month name and year from datetime string

I have a json containing field Month having string datetime-

{
 Month : "31-Jan-2022 12:00 AM (EST)"
 ....
 ....
}

How can I fetch Month Name and Year from this string using date functions in javascript?

I need output to be Jan-2022

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

let str = "31-Jan-2022 12:00 AM (EST)"
let date = new Date(str)
const month = date.toLocaleString('default', { month: 'long' });
const year = date.getFullYear()
console.log(month,year);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading