Date changes from milliseconds to String whenever state updates

333

I have a chatbox with bunch of messages, i wanna display a date obviously and it comes in terms of milliseconds i can easily convert from milliseconds to real time with toDate() method, but the problem is whenever i type a new message (state updates), it sends me a new date as a String,throwing me an error because i seemingly can’t use toDate() on it.

You can basically see it on the screenshot, they are from a console.log of the same line.

P.S i create a date with new Date() method.

new Date() returns date object.
Try Date.now().

1 Like

Show the relevant bit of the code, a picture of some console logs is not very easy to debug.

thanks, that helped a ton. Today i learned something new. new Date() returns an object with seconds and milliseconds and Date.now() returns just a number of seconds.

And i think i understand why new Date() temporarily switches to string and shows the whole date instead of an object, when a new message is created. Possibly because when it updates the date is new so it shows you the whole String, but when its even a second after that, it will show you an object of seconds,milliseconds…

Again thanks a ton.