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?
Asked
Active
Viewed 7.4k times
35

Roman
- 2,145
- 4
- 26
- 33
3 Answers
41
Use the valueOf
method on a moment object:
For local time:
moment().valueOf();
For UTC:
moment().utc().valueOf();

Mike
- 4,071
- 21
- 36
-
1These two return same value, so no need the second IMHO. – lk_vc Jan 16 '15 at 03:14
-
3Depends on where you reside and if your browser / system represents the actual timezone you are in ;) Then those two may differ... – Youp Bernoulli Aug 22 '16 at 13: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

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