React date formatting
-
What is the best way in react to convert a date from
2022-09-04T00:00:00
into
04/09/2022
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
-
What is the best way in react to convert a date from
2022-09-04T00:00:00
into
04/09/2022
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
I don't know about react, but the general answer is to use the date parser to convert to an internal time representation (eg Unix time, seconds since 1/1/1970...) then the date formatter to get what you want.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
-
What is the best way in react to convert a date from
2022-09-04T00:00:00
into
04/09/2022
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
Probably by using the Intl.DateTimeFormat[^] object, which is supported in all modern browsers.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
What is the best way in react to convert a date from
2022-09-04T00:00:00
into
04/09/2022
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
JavaScript's native date object does that.
const date = new Date(Date.parse('2022-09-04T00:00:00'));
console.log(date.toLocaleString());I would suggest putting a Z at the end of the ISO input date though, just to make it explicit that it's in UTC.
const date = new Date(Date.parse('2022-09-04T00:00:00Z'));
console.log(date.toLocaleString());Otherwise, JavaScript will assume the input is in the local time zone.
Jeremy Falcon