-1

So I have an axios call that fetches an object that looks like this...

    {
        "meeting_id": "982a4867-2b3e-41a7-a5e2-22d86094c980",
        "meeting_topic": "GCA Help",
        "created_at": "2022-10-31T20:30:33.568Z",
        "updated_at": "2022-10-31T20:30:33.568Z",
        "meeting_start_time": "2022-07-09T02:01:19",
        "meeting_end_time": "2022-07-09T03:01:19",
        "mentor_id": "882eb36a-d154-480d-89d4-a1cad1aa7330",
        "mentee_id": "50ef4f37-b8bd-4c93-a9a3-625e38c2c5cb",
        "admin_meeting_notes": "Meeting notes here!",
        "mentor_meeting_notes": "Mentor meeting notes",
        "mentee_meeting_notes": "Mentee meeting notes",
        "meeting_missed_by_mentee": "Attended",
        "user_id": "63447ddfe85cb425b0fed28e",
        "profile_id": "50ef4f37-b8bd-4c93-a9a3-625e38c2c5cb",
        "role": "mentee"
    }

I need to take the "meeting_start_time" keys, value, and parse it into a string of "MM/DD/YYYY". This will be stored in state, and used to render events using the AntD Calendar component.

I have attempted a regex solution which was way to messy.

I don't have access to the database schema to change the delivered format.

James
  • 35
  • 6

1 Answers1

0

To do this you can:

  • parse property with Date constructor
  • use toLocaleString to convert to MM/DD/YYYY, ...time format, then trim off time (by splitting the string by comma and getting first item)

const obj={meeting_id:"982a4867-2b3e-41a7-a5e2-22d86094c980",meeting_topic:"GCA Help",created_at:"2022-10-31T20:30:33.568Z",updated_at:"2022-10-31T20:30:33.568Z",meeting_start_time:"2022-07-09T02:01:19",meeting_end_time:"2022-07-09T03:01:19",mentor_id:"882eb36a-d154-480d-89d4-a1cad1aa7330",mentee_id:"50ef4f37-b8bd-4c93-a9a3-625e38c2c5cb",admin_meeting_notes:"Meeting notes here!",mentor_meeting_notes:"Mentor meeting notes",mentee_meeting_notes:"Mentee meeting notes",meeting_missed_by_mentee:"Attended",user_id:"63447ddfe85cb425b0fed28e",profile_id:"50ef4f37-b8bd-4c93-a9a3-625e38c2c5cb",role:"mentee"};

const date = new Date(obj.meeting_start_time).toLocaleString('en-US').split(',')[0]
console.log(date)