gpt4 book ai didi

javascript - 如何用当前日期添加 5 天并在 momentjs 中格式化输出?

转载 作者:行者123 更新时间:2023-12-03 09:51:52 25 4
gpt4 key购买 nike

当我在 momentjs 中添加 5 天和当前日期时,我面临将输出格式化为天/月/年的问题,即(25/08/2019)。

console.log( moment().add(5, 'days').calendar());

输出:

Sunday at 8:30 PM

但是当我添加 10 天时,即:

console.log( moment().add(10, 'days').calendar());

输出:

08/30/2019

我需要输出

moment().add(5, 'days').calendar() 

作为

25/08/2019

非常感谢您的帮助。

最佳答案

使用moment js的format方法

moment().add(5, 'days').format('DD/MM/YYYY') 

关于javascript - 如何用当前日期添加 5 天并在 momentjs 中格式化输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57576074/

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