Sometimes, we want to get current time in milliseconds with moment.js and JavaScript.
In this article, we’ll look at how to get current time in milliseconds with moment.js and JavaScript.
How to get current time in milliseconds with moment.js and JavaScript?
To get current time in milliseconds with moment.js and JavaScript, we use the valueOf
method.
For instance, we write
const timeInMilliseconds = moment().valueOf();
to call moment
to return an moment object with the current datetime.
And then we call valueOf
on it to return the timestamp of the current datetime in milliseconds.
Conclusion
To get current time in milliseconds with moment.js and JavaScript, we use the valueOf
method.