如何使用 JavaScript 计算两个日期之间的天数?
- How to get only 'day' from the date.
- How to get only 'month' from the date.
- How to get only 'Year' from the date.
- How to calculate 'year' from the 'days'
此类问题都有答案,请引用
最佳答案
您可以使用Moment.Js获取两个日期之间的差异,如下所示。
var start = moment("2015-13-08");
var end = moment("2015-13-08");
start.diff(end, "days")
要获取日、月、年,您可以使用 native javaScript。
var k = new Date();
k.getDate(); //gets the date
k.getMonth() + 1 ; //gets the month index (0-11) starting from 0, so u will get 7
// for August. Added +1 to get the month index on 1-12 scale
k.getFullYear() ; //gets the full year.
//Year from days
var years = days/365 ; //days is the no of days.
关于javascript - 如何在 JavaScript 中计算两个日期之间的天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31984739/