我正在使用MomentJS和当前moment().toObject()
输出
{
years:2016,
months:10,
date:3,
hours:18,
milliseconds:85,
minutes:26,
seconds:26
}
如何将输出格式更改为
{
year: 2016, //without 's'
month: 10, //without 's'
day: 3, // instead of date
...
}
答案 0 :(得分:1)
只需构建一个新对象:
var a = moment().toObject();
var b = { year: a.years, month: a.months + 1, day: a.date };
请注意,我将月份增加到占据输出0-11而不是1-12的时刻。你可能想要也可能不想要,但认为在这里指出它可能是有用的。