I want to get the Unix TimeStamp using Moment.js
I can find many functions which converts timestamp to date in moment.js
I know that i can easly get the unix timestamp by using the follwoing 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.
To find the Unix Timestamp in seconds:
moment().unix()
The documentation is your friend. :)
For anyone who finds this page looking for unix timestamp w/ milliseconds, the documentation says
moment().valueOf()
or
+moment();
you can also get it through moment().format('x')
(or .format('X')
[capital X] for unix seconds with decimal milliseconds), but that will give you a string. Which moment.js won't actually parse back afterwards, unless you convert/cast it back to a number first.
for UNIX time-stamp in milliseconds
moment().format('x') // lowerCase x
for UNIX time-stamp in seconds
moment().format('X') // capital X
Try any of these
valof = moment().valueOf(); // xxxxxxxxxxxxx
getTime = moment().toDate().getTime(); // xxxxxxxxxxxxx
unixTime = moment().unix(); // xxxxxxxxxx
formatTimex = moment().format('x'); // xxxxxxxxxx
unixFormatX = moment().format('X'); // xxxxxxxxxx