Reputation: 2175
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
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
Upvotes: 30
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
Reputation: 4091
Use the valueOf
method on a moment object:
For local time:
moment().valueOf();
For UTC:
moment().utc().valueOf();
Upvotes: 42