Home > other >  Convert an ISO date to DD:MM:YYYY HH:MM in Angular
Convert an ISO date to DD:MM:YYYY HH:MM in Angular

Time:11-23

I have my date in entry :

2022-11-21T21:07:56.830-07:00

And I would like to transform it like that:

21/11/2022 07:56

CodePudding user response:

You can use a third-party library like dayjs to format dates

In your case, you would need to do

dayjs('2022-11-21T21:07:56.830-07:00').format('DD/MM/YYYY hh:mm')

Although your input doesn't seem like an ISO date, indeed in console

new Date('2022-11-21T21:07:56.830-07:00')
Tue Nov 22 2022 05:07:56 GMT 0100 (Central European Standard Time)

So the output would be (for DD/MM/YYYY HH:mm)

22/11/2022 05:07

CodePudding user response:

You can refer to this https://www.npmjs.com/package/user-timezone npm package to convert dates into any specific format.

  • Related