Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

moment.js diff date formatting

Tags:

People also ask

How do you find the difference between two dates in a moment?

If you are using a date and time field and would like to output the difference between the two dates in days, hours and minutes, use the following template: var m1 = moment('{admission}', 'DD-MM-YYYY HH:mm'); var m2 = moment('{discharge}', 'DD-MM-YYYY HH:mm'); var m3 = m2. diff(m1,'minutes'); var m4 = m2.

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.

What does moment diff return?

Return Value: This function returns the date in milliseconds.


I'm using moment.js and want to calculate the difference between two timestamp,format them afterwards and display them in a div.

var diffTime = moment(1390310146.791877).diff( 1390309386.271075);

This gives me 760 seconds, but I want to format it like this:

(days, hrs, mins, secs) and only show days, hours and seconds if they are higher than 0.

How do I achieve that ?