Roman
Roman

Reputation: 2175

Moment.js: Date.now() javaScript analogue

Is there any simple way to get a number of milliseconds elapsed since 1 January 1970 00:00:00 UTC simular the Date.now() javaScript function?

Upvotes: 36

Views: 76871

Answers (3)

Abinash Pradhan
Abinash Pradhan

Reputation: 309

To get current date you may use the following line in your js file:

var currentDate = moment().format("DD-MM-YYYY");

It will show the date of the given format 19-Mar-2015

Click here to visit moment.js

Upvotes: 30

Ranjith Kumar
Ranjith Kumar

Reputation: 211

Date.now() is the simplest. Otherwise the following using simple javascript can be used:-

new Date().getTime()

Using moment.js

moment().valueOf() 

can be used.

moment("...").valueOf()

can be used to get the time elapsed since a particular date.

Upvotes: 13

Mike
Mike

Reputation: 4091

Use the valueOf method on a moment object:

For local time:

moment().valueOf();

For UTC:

moment().utc().valueOf();

Upvotes: 42

Related Questions