Assuming you have two Date
objects, you can just subtract them to get the difference in milliseconds:
var difference = date2 - date1;
From there, you can use simple arithmetic to derive the other values.
More Related Contents:
- How to get date for nearest Sunday at 15:00 JST?
- How to sort an object array by date property?
- Why does the month argument range from 0 to 11 in JavaScript’s Date constructor?
- How to check if DST (Daylight Saving Time) is in effect, and if so, the offset?
- Difference between dates in JavaScript
- JavaScript: Which browsers support parsing of ISO-8601 Date String with Date.parse
- How can I convert string to datetime with format specification in JavaScript?
- How to get the day of week and the month of the year?
- How to parse a time into a Date object from user input in JavaScript?
- Converting .NET DateTime to JSON [duplicate]
- Moment js date time comparison
- JavaScript – Get minutes between two dates
- How to show current time in JavaScript in the format HH:MM:SS?
- Convert MySql DateTime stamp into JavaScript’s Date format
- How to JSON stringify a javascript Date and preserve timezone
- moment.js – UTC gives wrong date
- How to convert time in milliseconds to hours, min, sec format in JavaScript?
- Sort a string date array
- How do I do a Date comparison in Javascript? [duplicate]
- Compute elapsed time [duplicate]
- Javascript show milliseconds as days:hours:mins without seconds
- Javascript Convert Date Time string to Epoch
- Why isn’t “2016-02-16” equal to “2016-02-16 00:00”?
- from unix timestamp to datetime
- Javascript return number of days,hours,minutes,seconds between two dates
- Javascript to convert UTC to local time
- Round a timestamp to the nearest date
- Javascript, Time and Date: Getting the current minute, hour, day, week, month, year of a given millisecond time
- Hot to get incomplete datetime-local input values
- Converting Google spreadsheet date into a JS Date object?