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 change my this date format "20221015T000000Z" into yyyy-mm-dd (2022-10-31)?

i want to change my date format from "20221015T000000Z" to yyyy-mm-dd. i tried looking up solutions but not able to find anything relatable.

>Solution :

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

The example date string already contains all the information you need in clear text. It’s not a standard date string, but assuming the format of the string is always going to be like that, all you have to do is to extract the substrings and stitch them back together using the - separator.

This is exactly what this function does by using String’s substr method and Array’s join method:

const parseDateString = s => [s.substr(0,4), s.substr(4,2), s.substr(6,2)].join('-');

Usage:

const result = parseDateString('20221015T000000Z');
// do something with result, e.g. console.log(result)
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