Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

moment.js get current time in milliseconds?

People also ask

How do you find time in a milliseconds moment?

To get current time in milliseconds with moment. js and JavaScript, we use the valueOf method. const timeInMilliseconds = moment(). valueOf();

How can I get current time in moment?

To get the current date and time, just call javascript moment() with no parameters like so: var now = moment();

What is Moment () hour ()?

The moment(). hour() Method is used to get the hours from the current time or to set the hours. Syntax: moment().hour(); or. moment().

Is MomentJS deprecated?

Moment construction falls back to js Date. This is discouraged and will be removed in an upcoming major release. This deprecation warning is thrown when no known format is found for a date passed into the string constructor.


From the docs: http://momentjs.com/docs/#/parsing/unix-timestamp-milliseconds/

So use either of these:


moment(...).valueOf()

to parse a preexisting date and convert the representation to a unix timestamp


moment().valueOf()

for the current unix timestamp


See this link http://momentjs.com/docs/#/displaying/unix-timestamp-milliseconds/

valueOf() is the function you're looking for.

Editing my answer (OP wants milliseconds of today, not since epoch)

You want the milliseconds() function OR you could go the route of moment().valueOf()


var timeArr = moment().format('x');

returns the Unix Millisecond Timestamp as per the format() documentation.


You could subtract the current time stamp from 12 AM of the same day.

Using current timestamp:

moment().valueOf() - moment().startOf('day').valueOf()

Using arbitrary day:

moment(someDate).valueOf() - moment(someDate).startOf('day').valueOf()