gpt4 book ai didi

javascript - moment().toObject() 输出格式

转载 作者:行者123 更新时间:2023-12-03 05:44:01 24 4
gpt4 key购买 nike

我正在使用 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
...
}

最佳答案

只需构建一个新对象:

var a = moment().toObject();
var b = { year: a.years, month: a.months + 1, day: a.date };

请注意,我增加了月份以考虑输出月份 0-11 而不是 1-12 的时刻。您可能想要也可能不想要,但认为在这里指出可能有用。

关于javascript - moment().toObject() 输出格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40407007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com