Source From Here
Question
Im trying to figure out a way to get the time difference in seconds between two dates. For example, difference in seconds between:
How-To
You can leverage moment module:
More usage on
moment module:
Supplement
* FAQ - How to format a JavaScript date
* FAQ - Moment.js transform to date object
* W3CSchool - JavaScript Date Reference
* npm - moment: A lightweight JavaScript date librar...ulating, and formatting dates.
Question
Im trying to figure out a way to get the time difference in seconds between two dates. For example, difference in seconds between:
How-To
You can leverage moment module:
- var moment = require('moment')
- var startDate = moment('2013-5-11 8:37:18', 'YYYY-M-DD HH:mm:ss')
- var endDate = moment('2013-5-11 10:37:18', 'YYYY-M-DD HH:mm:ss')
- var secondsDiff = endDate.diff(startDate, 'seconds')
- console.log(secondsDiff) // Output 7200
Supplement
* FAQ - How to format a JavaScript date
* FAQ - Moment.js transform to date object
* W3CSchool - JavaScript Date Reference
* npm - moment: A lightweight JavaScript date librar...ulating, and formatting dates.
沒有留言:
張貼留言