learner
learner

Reputation: 69

moment js time and date are not the same

API RESPONSE :

created_on: "2022-06-06T12:00:37.000Z"

UI CODE :

 <div style={{whiteSpace: 'nowrap'}}>Created On :</div> 
<b style={{ marginLeft: '20px', fontSize: 15 }}>{createdOn ? moment.utc(createdOn).format('MMMM Do YYYY, HH:mm a') : ''}</b>

OUTPUT :

JUNE 16th 2022, 10:28 am

EXPECTED OUTPUT :

JUNE 6th 2022, 12:00 am

thnx in advance.

Upvotes: 0

Views: 84

Answers (1)

Dave
Dave

Reputation: 172

Add your "createdOn" variable to inside moment() not on utc.

 <div style={{whiteSpace: 'nowrap'}}>Created On :</div> 
<b style={{ marginLeft: '20px', fontSize: 15 }}>{createdOn ? moment(createdOn).utc().format('MMMM Do YYYY, HH:mm a') : ''}</b>

Upvotes: 2

Related Questions