gpt4 book ai didi

javascript - Moment.js : Segmenting a duration into Years, 月、周、日等

转载 作者:行者123 更新时间:2023-11-30 20:09:22 24 4
gpt4 key购买 nike

moment 提供这种便利吗?

如果我有两个日期,我可以从我可以解构信息的时刻获取一个对象吗:

const now = moment();
const futureDay = moment('27-09-2019', 'DD-MM-YYYY');
const timeDiff = futureDay.diff(now);

// ... some code here to get an object with the timeDiff

const {years, months, weeks, days} = theDiffObject;
...

最佳答案

是的,您可以使用 durations .像这样:

const theDiffObject = {
years: moment.duration(timeDiff).years(),
months: moment.duration(timeDiff).months(),
weeks: moment.duration(timeDiff).weeks(),
days: moment.duration(timeDiff).days()
}

关于javascript - Moment.js : Segmenting a duration into Years, 月、周、日等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52558554/

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