0
其实,我被困在一个与Date有关的问题中。如何在原生反应中减去和加上日期
我想在原生反应中减去并加上日期。
有没有关于它的任何解决方案。
我已经使用Moment.js,但错误发生在它所以请帮助我。
预先感谢您
其实,我被困在一个与Date有关的问题中。如何在原生反应中减去和加上日期
我想在原生反应中减去并加上日期。
有没有关于它的任何解决方案。
我已经使用Moment.js,但错误发生在它所以请帮助我。
预先感谢您
下面使用什么工作的例子加减日期,月份和日期的检查:
一日
let tomorrow = new Date();
tomorrow = moment(tomorrow).add(1, 'day').format('YYYY-MM-DD'); // for specific format
let today = moment(new Date()).format('YYYY-MM-DD');
let tomorrow = new Date();
tomorrow = moment(tomorrow).add(1, 'day').format('YYYY-MM-DD');
单月
moment(currentMonth).add(1, 'month');
moment(currentMonth).subtract(1, 'month');
对于日期
let now = "14/11/2016";
let then = "03/12/2017";
let diff = moment(now,"DD/MM/YYYY").diff(moment(then,"DD/MM/YYYY"));
let duration = moment.duration(diff);
let result = duration.format("hh:mm:ss");
请参阅详细的时间差:https://stackoverflow.com/a/18624295/6592263
编辑(未测试)
要获得月
let d = moment(new Date());
d.month(); // month number
d.format('ddd MMM DD YYYY');
获取年份
let d = moment(new Date());
d.year() // year
Wowww很酷的男人。感谢很多。它对我很有帮助。再次感谢 –
还有一件事。如果我想减去并添加一年,以便与上述月份相同。 –
,你能告诉我如何减去一个月..实际上我得到了一个错误。 –