I have a MongoDB collection which contains some data created by users. I want to get exact time from createdAt filed. Please see the below image.
See the createdAt timestamp for a data created on 2023-08-17 22:30:02.
I’m building a next.js app. I’m able to split date from the timestamp using slice() method. But time given here is in some another format. Can anyone help me to get the time in standard format?
>Solution :
There are some library exist that format you date and time and also make them separate.
But you can achieve same thing with JavaScript as well.
`${new Date('2023-08-17 22:30:02').getHours()}
:${new Date('2023-08-17 22:30:02').getMinutes()}
:${new Date('2023-08-17 22:30:02').getSeconds()}`
