Getting current unixtimestamp using Moment.js

chandan picture chandan · Aug 26, 2014 · Viewed 171.1k times · Source

I want to get the Unix TimeStamp using Moment.js. I can find many functions which convert timestamp to date in moment.js. I know that I can easily get the unix timestamp by using the following JavaScript function: Math.floor(new Date().getTime()/1000).

But I want to use Moment.js to get the same result. Is there any direct function in moment.js to get the current timestamp?

Answer

Matt Johnson-Pint picture Matt Johnson-Pint · Aug 26, 2014

To find the Unix Timestamp in seconds:

moment().unix()

The documentation is your friend. :)