moment.js获取当前时间往前的时间、两个时间差

moment().format("YYYY-MM-DD HH:mm:ss"); //当前时间

moment().subtract(7, "days").format("YYYY-MM-DD"); //当前时间的前7天时间

moment().subtract(1, "years").format("YYYY-MM-DD"); //当前时间的前1年时间

moment().subtract(3, "months").format("YYYY-MM-DD"); //当前时间的前3个月时间

moment().subtract(1, "weeks").format("YYYY-MM-DD"); //当前时间的前一个星期时间

 

两个日期/时间的时差:

moment(endTime).diff(moment(startTime), 'years')

moment(endTime).diff(moment(startTime), 'months')

moment(endTime).diff(moment(startTime), 'days')    //  开始时间和结束时间的时间差,以“天”为单位;endTime和startTime都是毫秒数

moment(endTime).diff(moment(startTime),'minutes' )

moment(endTime).diff(moment(startTime), 'seconds')

你可能感兴趣的:(moment.js获取当前时间往前的时间、两个时间差)