Home > Blockchain >  Changing date format from "Jun 02, 2022 at 05:55 AM CDT" to "06/02/2022 at 05:55 AM&q
Changing date format from "Jun 02, 2022 at 05:55 AM CDT" to "06/02/2022 at 05:55 AM&q

Time:06-10

I need to change a date format from "Jun 02, 2022 at 05:55 AM CDT" to "06/02/2022 at 05:55 AM". I tried many date conversions, but I am not getting the result I want.

order.messageSentOn = new Intl.DateTimeFormat('en-US').format(dbDate);

Any help is appreciated. Thank you.

CodePudding user response:

Install moment

yarn add moment
// Or
npm i moment

Uses

import moment from "moment"

// ......

const date= "Jun 02, 2022 at 05:55 AM";

const formatedDate = moment(date).format("MM/DD/YYYY HH:mm A")

Your code

const tempData= data.map((order) => {
          order.messageSentOn = moment(order.messageSentOn).format("MM/DD/YYYY HH:mm A");
    return order;
        });
        setDocumentsTable(tempData);
  • Related