Sometimes, we want to convert Firebase timestamp to date and time with JavaScript.
In this article, we’ll look at how to convert Firebase timestamp to date and time with JavaScript.
How to convert Firebase timestamp to date and time with JavaScript?
To convert Firebase timestamp to date and time with JavaScript, we use the Date
constructor.
For instance, we write
const timestamp = { nanoseconds: 0, seconds: 1562524200 };
console.log(new Date(timestamp.seconds * 1000));
We convert seconds
to milliseconds by multiplying it by 1000.
Then we pass it into the Date
constructor to convert it into a Date
object.
Conclusion
To convert Firebase timestamp to date and time with JavaScript, we use the Date
constructor.