35

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?

Roman
  • 2,145
  • 4
  • 26
  • 33

3 Answers3

41

Use the valueOf method on a moment object:

For local time:

moment().valueOf();

For UTC:

moment().utc().valueOf();
Mike
  • 4,071
  • 21
  • 36
29

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

userlond
  • 3,632
  • 2
  • 36
  • 53
Abinash Pradhan
  • 299
  • 3
  • 3
13

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.

Ranjith Kumar
  • 201
  • 2
  • 6