微信小程序关于时间运算

data里的数组中每个元素都存放多个对象,其中有一个对象是时间(暂定util.formatTime(new Date)的格式,需要年月日,可以改)
想要做到时间加减(时间不定,暂定30分钟),同时想要显示在wxml(new data()的格式在前台会显示[object object],想要显示时分秒)
想问一下有没有可能让对象为new date()情况下同时解决前台只显示时分秒
或者util.formatTime(new Date)的格式在后台进行简单换算,还是说根据“:”拆分?


const time = new Date(),
    hour = time.getHours() > 9 ? time.getHours() : ('0' + time.getHours()),
    minute = time.getMinutes() > 9 ? time.getMinutes() : ('0' + time.getMinutes()),
    second = time.getSeconds() > 9 ? time.getSeconds() : ('0' + time.getSeconds());
console.log(hour + ':' + minute + ':' + second);

显示[object object]是因为你确实扔进来一个对象,想看具体值需要拿出对象内的值。
new date()本身就是时间戳了,就不要format掉,时间戳计算时间很方便的。加个应该是30分钟60秒1000毫秒就是往后30分钟吧