Javascript Moment.js:将持续时间分为年、月、周、日等
时刻是否提供了这种便利 若我有两个日期,我可以从那个一刻起得到一个对象,从那个一刻起我可以分解信息,如:Javascript Moment.js:将持续时间分为年、月、周、日等,javascript,momentjs,Javascript,Momentjs,时刻是否提供了这种便利 若我有两个日期,我可以从那个一刻起得到一个对象,从那个一刻起我可以分解信息,如: const now = moment(); const futureDay = moment('27-09-2019', 'DD-MM-YYYY'); const timeDiff = futureDay.diff(now); // ... some code here to get an object with the timeDiff const {years, months, we
const now = moment();
const futureDay = moment('27-09-2019', 'DD-MM-YYYY');
const timeDiff = futureDay.diff(now);
// ... some code here to get an object with the timeDiff
const {years, months, weeks, days} = theDiffObject;
...
是的,你可以用。大概是这样的:
const theDiffObject = {
years: moment.duration(timeDiff).years(),
months: moment.duration(timeDiff).months(),
weeks: moment.duration(timeDiff).weeks(),
days: moment.duration(timeDiff).days()
}
哇,我只是需要多一点创意。非常感谢@Darren。