Date string from POST API response to different format | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Date string from POST API response to different format

Hi everyone! I have an array from an api response and it gives me the <startdate></startdate> as a string in the iso format. That’s fine, but I want to convert it to something simple like mm-dd-yyyy. Can anyone suggest how I can use typescript to reformat the response into a different output?

14th Oct 2021, 3:11 AM
Matthew Goodman
3 Answers
+ 1
use date=new Date(iso_date) and your can format with Date object https://www.javatpoint.com/typescript-date-object
15th Oct 2021, 6:00 PM
Nyashi
0
Thank you Nyashi! Ill try it out when I get off work.
15th Oct 2021, 6:50 PM
Matthew Goodman
0
You can use moment library, First install it, 2nd import moment in your desire component 3rd update format like moment(new Date(api_date)). format('MM-DD-YYYY')
1st Jan 2022, 5:35 PM
Asim Ilyas
Asim Ilyas - avatar