I'm trying to pass this props.data.STDout
which is a string in this format "2022-04-29 14:05:00" from UTC to local time.
I've tried but it doesn't work, do you have any ideas?
let newDate = new Date(props.data.STDout);
let newDate2 = newDate.toString()
Thank you very much!
CodePudding user response:
Try
let newDate2 = newDate.toLocaleString()
CodePudding user response:
I got it!
Just needed to add UTC
to the original date string, so this is how it looks working perfectly:
let newDate = new Date(`${props.data.STDOut} UTC`);
let newDate2 = newDate.toString();
As props.data.STDOut
is a string you should use the literal `${}`
to wrap it and be able to add UTC
to it, then just parse toString, and done.
It might be a more elegant solution, but for now, if it works, it works.
Thanks guys!